Skip to content

Commit

Permalink
add sort index for sources
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Dec 2, 2024
1 parent a42b5e4 commit f138d52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions modules/query.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ declare function query:get-normalized-date($doc as document-node()) as xs:date?
case 'diaries' return $doc/tei:ab/data(@n)
case 'news' return $doc//tei:date[parent::tei:publicationStmt]/substring(@when,1,10)
case 'documents' return date:getOneNormalizedDate($doc//tei:creation/tei:date, true())
case 'sources' return
(
date:getOneNormalizedDate(($doc//tei:sourceDesc//tei:imprint/tei:date)[1], true()),
date:getOneNormalizedDate(($doc//mei:creation/mei:date)[1], true()),
date:getOneNormalizedDate(($doc/mei:manifestation/mei:pubStmt/mei:date)[1], true())
)[1]
default return ()
return
if($date castable as xs:date) then $date cast as xs:date
Expand Down
11 changes: 9 additions & 2 deletions modules/wdt.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,21 @@ declare function wdt:sources($item as item()*) as map(*) {
()
},
'sort' : function($params as map(*)?) as document-node()* {
$item
if(sort:has-index('sources')) then ()
else (wdt:sources(())('init-sortIndex')()),
for $i in wdt:sources($item)('filter')() order by sort:index('sources', $i) ascending return $i
},
'init-collection' : function() as document-node()* {
crud:data-collection('sources')[descendant::mei:titleStmt][not(descendant::mei:annot[@type='no-ordinary-record'])] |
crud:data-collection('sources')[descendant::tei:titleStmt/tei:title = 'WeGA, Textquellen, Digitale Edition']
},
'init-sortIndex' : function() as item()* {
()
sort:create-index-callback('sources', wdt:sources(())('init-collection')(), function($node) {
let $date := query:get-normalized-date($node)
return
(if(exists($date)) then $date else '0000') ||
$node//*:title[1]
}, ())
},
'title' : function($serialization as xs:string) as item()? {
let $source :=
Expand Down

0 comments on commit f138d52

Please sign in to comment.