forked from mikolajserafin/serafin7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xql
76 lines (65 loc) · 2.61 KB
/
index.xql
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
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:persons := doc('/db/apps/serafin/data/auxiliary/authorityLists.xml');
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
;
(:~
: 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 "title" return
string-join((
$header//tei:msDesc/tei:head, $header//tei:titleStmt/tei:title[@type = 'main'],
$header//tei:titleStmt/tei:title
), " - ")
case "author" return
for $p in $header//tei:correspDesc/tei:correspAction/tei:persName/@ref
return
idx:resolve-person($p)
case "place" return
for $p in $header//tei:correspDesc/tei:correspAction/tei:placeName/@ref
return
idx:resolve-place($p)
case "language" return
$root//tei:text[@type='source']/@xml:lang
case "number" return
idx:pad-number(substring($root/@xml:id, 3), 2)
case "date" return
$header//tei:correspDesc/tei:correspAction/tei:date/@when
case "year" return
substring($header//tei:correspDesc/tei:correspAction/tei:date/@when, 1, 4)
case "genre" return
'Letter'
default return
()
};
declare function idx:resolve-person($key) {
$idx:persons/id(substring-after($key, '#'))/tei:persName
};
declare function idx:resolve-place($key) {
$idx:persons/id(substring-after($key, '#'))/tei:placeName
};
declare function idx:pad-number($number as xs:anyAtomicType?, $length as xs:integer) as xs:string {
if ($length > string-length(string($number)))
then
'0' || string($number)
else
$number
} ;