Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filter option for "facsimile available" #361

Merged
merged 14 commits into from
Sep 16, 2020
Merged
Next Next commit
first shot at implementing #359
  • Loading branch information
peterstadler committed Sep 14, 2020
commit 496fa18d95969c91c7c31be3e217b181d7b957f9
5 changes: 4 additions & 1 deletion catalogues/dictionary_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,7 @@
<entry xml:id="nextMatch">Nächstes Suchergebnis</entry>
<entry xml:id="dataMigratedFrom">Datenübernahme aus</entry>
<entry xml:id="furtherInformationSeeThere">weitere Informationen siehe dort</entry>
</dictionary>
<entry xml:id="internal">intern (WeGA)</entry>
<entry xml:id="external">extern</entry>
<entry xml:id="without">ohne</entry>
</dictionary>
5 changes: 4 additions & 1 deletion catalogues/dictionary_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,7 @@
<entry xml:id="nextMatch">Next Match</entry>
<entry xml:id="dataMigratedFrom">Data migrated from</entry>
<entry xml:id="furtherInformationSeeThere">further information see there</entry>
</dictionary>
<entry xml:id="internal">internal (WeGA)</entry>
<entry xml:id="external">external</entry>
<entry xml:id="without">without</entry>
</dictionary>
11 changes: 11 additions & 0 deletions modules/api.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,17 @@ declare function api:validate-repository($model as map()) as map()? {
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "repository".' )
};


(:~
: Check parameter facsimile ('internal','external','without')
: multiple values allowed as input, either by providing multiple URL parameters
: or by sending a comma separated list as the value of one URL parameter
~:)
declare function api:validate-facsimile($model as map()) as map()? {
if(xmldb:decode-uri($model?facsimile) = ('internal','external','without')) then $model
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "facsimile". Must be one of "internal", "external", or "without".')
};

(:~
: Fallback for unknown API parameters
: Simply returns an error message
Expand Down
29 changes: 28 additions & 1 deletion modules/facets.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare
let $facet := $node/data(@name)
let $selected := $model?filters?($facet)
let $selectedObjs as array(*)? :=
if(count($selected) gt 0) then facets:createFacets($model?search-results, $facet, -1, $lang)
if(count($selected) gt 0) then facets:facets($model?search-results, $facet, -1, $lang)
else ()
return
element {name($node)} {
Expand Down Expand Up @@ -67,6 +67,7 @@ declare
declare function facets:facets($nodes as node()*, $facet as xs:string, $max as xs:integer, $lang as xs:string) as array(*) {
switch($facet)
case 'textType' return facets:from-docType($nodes, $facet, $lang)
case 'facsimile' return facets:facsimile($nodes, $facet, $lang)
default return facets:createFacets($nodes, $facet, $max, $lang)
};

Expand All @@ -84,6 +85,32 @@ declare %private function facets:from-docType($collection as node()*, $facet as
]
};

declare %private function facets:facsimile($collection as node()*, $facet as xs:string, $lang as xs:string) as array(*) {
let $facsimiles := $collection ! query:facsimile(.)
let $external := count($facsimiles[@sameAs]/root())
let $internal := count($facsimiles[not(@sameAs)][tei:graphic]/root())
let $noFacs := count($collection) - $external - $internal
return
[
map {
'value' : 'internal',
'label' : lang:get-language-string('internal', $lang),
'frequency' : $internal
},
map {
'value' : 'external',
'label' : lang:get-language-string('external', $lang),
'frequency' : $external
},
map {
'value' : 'without',
'label' : lang:get-language-string('without', $lang),
'frequency' : $noFacs
}
]
};


(:~
: Create facets
:
Expand Down
12 changes: 11 additions & 1 deletion modules/search.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare variable $search:valid-params := ('biblioType', 'editors', 'authors', 'w
'occupations', 'docSource', 'composers', 'librettists', 'lyricists', 'dedicatees', 'journals',
'docStatus', 'addressee', 'sender', 'textType', 'residences', 'places', 'placeOfAddressee', 'placeOfSender',
'fromDate', 'toDate', 'undated', 'hideRevealed', 'docTypeSubClass', 'sex', 'surnames', 'forenames',
'asksam-cat', 'vorlageform', 'einrichtungsform', 'placenames', 'repository');
'asksam-cat', 'vorlageform', 'einrichtungsform', 'placenames', 'repository', 'facsimile');

(:~
: Main function called from the templating module
Expand Down Expand Up @@ -302,6 +302,7 @@ declare %private function search:filter-result($collection as document-node()*,
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 * {()} )
else if($filter = 'textType') then search:textType-filter($collection, $filters)
else if($filter = 'hideRevealed') then search:revealed-filter($collection, $filters)
else if($filter = 'facsimile') then search:facsimile-filter($collection, $filters)
(: exact search for terms -> range:eq :)
else if($filter = ('journals', 'forenames', 'surnames', 'sex', 'occupations')) then query:get-facets($collection, $filter)[range:eq(.,$filters($filter))]/root()
(: range:contains for tokens within key values :)
Expand Down Expand Up @@ -350,6 +351,15 @@ declare %private function search:revealed-filter($collection as document-node()*
$collection//tei:correspDesc[not(@n='revealed')]/root()
};

declare %private function search:facsimile-filter($collection as document-node()*, $filters as map(*)) as document-node()* {
let $facsimiles := $collection ! query:facsimile(.)
return
switch($filters?facsimile)
case 'internal' return $facsimiles[not(@sameAs)][tei:graphic]/root()
case 'external' return $facsimiles[@sameAs]/root()
default return $collection except $facsimiles/root()
};

(:~
:
~:)
Expand Down
2 changes: 2 additions & 0 deletions templates/ajax/correspondence.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ <h4 data-template="lang:translate">works</h4>
<select multiple="multiple" data-template="facets:select" name="works"/>
<h4 data-template="lang:translate">repository</h4>
<select multiple="multiple" data-template="facets:select" name="repository"/>
<h4 data-template="lang:translate">facsimile</h4>
<select multiple="multiple" data-template="facets:select" name="facsimile"/>
<h4 data-template="lang:translate">docStatus</h4>
<select multiple="multiple" data-template="facets:select" name="docStatus"/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions templates/ajax/documents.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ <h4 data-template="lang:translate">docType</h4>
<h4 data-template="lang:translate">repository</h4>
<select multiple="multiple" data-template="facets:select" name="repository"/>

<h4 data-template="lang:translate">facsimile</h4>
<select multiple="multiple" data-template="facets:select" name="facsimile"/>

<h4 data-template="lang:translate">docStatus</h4>
<select multiple="multiple" data-template="facets:select" name="docStatus"/>
</div>
Expand Down