Skip to content

Commit c0173b0

Browse files
committed
provide backend functionality for chronology facet
1 parent 1f040b7 commit c0173b0

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

api/v1/openapi/schemas/facets.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ enum:
55
- asksam-cat
66
- authors
77
- biblioType
8+
- chronology
89
- composers
910
- dedicatees
1011
- docLang

modules/api.xqm

+10
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,16 @@ declare function api:validate-workTitle($model as map(*)) as map(*)? {
11301130
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "workTitle".')
11311131
};
11321132

1133+
(:~
1134+
: Check parameter chronology
1135+
: only one value allowed
1136+
~:)
1137+
declare function api:validate-chronology($model as map(*)) as map(*)? {
1138+
if(every $i in $model?chronology ! tokenize(., ',') satisfies matches($i, '^(((\d{4}–)?\d{4})|\d{2})$'))
1139+
then map { 'chronology': ($model?chronology ! tokenize(., ',')) }
1140+
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "chronology". It must be a comma separated list of strings matching the pattern "^(((\d{4}–)?\d{4})|\d{2})$", e.g. "1800–1899,1870–1879,1876"')
1141+
};
1142+
11331143
(:~
11341144
: Fallback for unknown API parameters
11351145
: Simply returns an error message

modules/search.xqm

+18
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ declare %private function search:filter-result($collection as document-node()*,
324324
if($filter = ('undated')) then ($collection intersect core:undated($docType))/root()
325325
else if($filter = 'searchDate') then search:searchDate-filter($collection, $filters($filter)[1])
326326
else if($filter = ('fromDate', 'toDate')) then wdt:lookup($docType, $collection)?filter-by-date(try {$filters?fromDate cast as xs:date} catch * {()}, try {$filters?toDate cast as xs:date} catch * {()} )
327+
else if($filter = 'chronology') then search:chronology-filter($collection, $filters($filter))
327328
else if($filter = 'textType') then search:textType-filter($collection, $filters($filter)[1])
328329
else if($filter = 'hideRevealed') then search:revealed-filter($collection)
329330
else if($filter = 'facsimile') then search:facsimile-filter($collection, $filters($filter)[1])
@@ -338,6 +339,9 @@ declare %private function search:filter-result($collection as document-node()*,
338339
if($filter = ('fromDate', 'toDate')) then
339340
try { map:remove(map:remove($filters, 'toDate'), 'fromDate') }
340341
catch * {()}
342+
else if($filter = 'chronology') then
343+
try { map:remove($filters, 'chronology') }
344+
catch * {()}
341345
else if(count($filters($filter)) gt 1) then
342346
map:merge(($filters, map:entry($filter, subsequence($filters($filter), 2))))
343347
else
@@ -351,6 +355,20 @@ declare %private function search:filter-result($collection as document-node()*,
351355
else $collection
352356
};
353357

358+
(:~
359+
: Helper function for search:filter-result()
360+
: Queries the date facet from the index
361+
:)
362+
declare %private function search:chronology-filter($collection as document-node()*, $dateTokens as xs:string*) as document-node()* {
363+
let $options := map {
364+
'facets': map {
365+
'date': $dateTokens
366+
}
367+
}
368+
return
369+
$collection/tei:TEI[ft:query(., (), $options)]/root()
370+
};
371+
354372
(:~
355373
: Helper function for search:filter-result()
356374
: Queries dates within TEI and MEI documents

0 commit comments

Comments
 (0)