-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.xql
More file actions
138 lines (127 loc) · 5.21 KB
/
Copy pathindex.xql
File metadata and controls
138 lines (127 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
xquery version "3.1";
module namespace idx="http://teipublisher.com/index";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace dbk="http://docbook.org/ns/docbook";
declare variable $idx:app-root :=
let $rawPath := system:get-module-load-path()
return
(: strip the xmldb: part :)
if (starts-with($rawPath, "xmldb:exist://")) then
if (starts-with($rawPath, "xmldb:exist://embedded-eXist-server")) then
substring($rawPath, 36)
else
substring($rawPath, 15)
else
$rawPath
;
declare variable $idx:registers := collection($idx:app-root || '/data/registers');
(:~
: Helper function called from collection.xconf to create index fields and facets.
: This module needs to be loaded before collection.xconf starts indexing documents
: and therefore should reside in the root of the app.
:)
declare function idx:get-metadata($root as element(), $field as xs:string) {
let $header := $root/tei:teiHeader
return
switch ($field)
case "persName" return
for $p in $header//tei:correspDesc/tei:correspAction/tei:persName/@key
return
idx:resolve-person($p)
case "person" return
for $persName in (
$header//tei:correspDesc/tei:correspAction/tei:persName/@key,
$root//tei:text//tei:persName/@key
)
return
$persName
case "place" return
for $placeName in (
$header//tei:correspDesc/tei:correspAction/tei:placeName/@key,
$root//tei:text//tei:placeName/@key
)
return
$placeName
case "year" return
substring($header//tei:correspDesc/tei:correspAction/tei:date/@when, 1, 4)
case "title" return
string-join((
$header//tei:msDesc/tei:head, $header//tei:titleStmt/tei:title[@type = 'main'],
$header//tei:titleStmt/tei:title,
$root/dbk:info/dbk:title,
root($root)//article-meta/title-group/article-title,
root($root)//article-meta/title-group/subtitle
), " - ")
case "language" return
head((
$header//tei:langUsage/tei:language/@ident,
(: rule for Serafin letters :)
$root//tei:text[@type="source"]/@xml:lang,
$root/@xml:lang,
$header/@xml:lang,
root($root)/*/@xml:lang
))
case "date" return
idx:get-date(($header//tei:correspDesc/tei:correspAction[@type="sent"]/tei:date[1]))
case "genre" return (
idx:get-genre($header),
root($root)//dbk:info/dbk:keywordset[@role="genre"]/dbk:keyword,
root($root)//article-meta/kwd-group[@kwd-group-type="genre"]/kwd
)
case "category" return
(root($root)/tei:TEI/@n, "ZZZ")[1]
case "feature" return (
idx:get-classification($header, 'feature'),
$root/dbk:info/dbk:keywordset[@role="feature"]/dbk:keyword
)
case "form" return (
idx:get-classification($header, 'form'),
$root/dbk:info/dbk:keywordset[@role="form"]/dbk:keyword
)
case "period" return (
idx:get-classification($header, 'period'),
$root/dbk:info/dbk:keywordset[@role="period"]/dbk:keyword
)
case "content" return (
root($root)//body,
$root/dbk:section
)
default return
()
};
declare function idx:resolve-person($key) {
$idx:registers/id($key)/tei:persName
};
declare function idx:resolve-place($key) {
$idx:registers/id($key)/tei:placeName
};
declare function idx:get-genre($header as element()?) {
for $target in $header//tei:textClass/tei:catRef[@scheme="#genre"]/@target
let $category := id(substring($target, 2), doc($idx:app-root || "/data/taxonomy.xml"))
return
$category/ancestor-or-self::tei:category[parent::tei:category]/tei:catDesc
};
declare function idx:get-classification($header as element()?, $scheme as xs:string) {
for $target in $header//tei:textClass/tei:catRef[@scheme="#" || $scheme]/@target
let $category := id(substring($target, 2), doc($idx:app-root || "/data/taxonomy.xml"))
return
$category/ancestor-or-self::tei:category[parent::tei:category]/tei:catDesc
};
declare function idx:get-date($date) {
if($date/@when)
then xs:date(idx:normalize-date($date/@when/string()))
else if($date/@notBefore)
then xs:date(idx:normalize-date($date/@notBefore/string()))
else if($date/@notAfter)
then xs:date(idx:normalize-date($date/@notAfter/string()))
else (
)
};
declare function idx:normalize-date($date as xs:string) {
if (matches($date, "^\d{4}-\d{2}$")) then
$date || "-01"
else if (matches($date, "^\d{4}$")) then
$date || "-01-01"
else
$date
};