Skip to content

Commit

Permalink
Merge pull request #361 from Edirom/issue-359
Browse files Browse the repository at this point in the history
add filter option for "facsimile available"
  • Loading branch information
peterstadler authored Sep 16, 2020
2 parents c5c1ea6 + 449494f commit 6061bfd
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 93 deletions.
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>
162 changes: 91 additions & 71 deletions modules/api.xqm

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions 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 {node-name($node)} {
Expand All @@ -54,19 +54,24 @@ declare
for $i in $selected
(: let $log := util:log-system-out($i):)
let $display-term := facets:display-term($facet, $i, $lang)
order by $display-term
let $freq :=
if ($selectedObjs?*[?value = $i]?frequency castable as xs:int)
then $selectedObjs?*[?value = $i]?frequency
else 0
order by $display-term
return
element option {
attribute selected {'selected'},
attribute value {$i},
$display-term || ' (' || $selectedObjs?*[?value = $i]?frequency || ')'
$display-term || ' (' || $freq || ')'
}
}
};

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 +89,40 @@ 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 := $facsimiles[@sameAs]/root()
let $internal := $facsimiles[not(@sameAs)][tei:graphic]/root()
let $internalCount := count($internal)
let $externalCount := count($external)
let $noFacsCount := count($collection) - count($external | $internal)
return
array {
if($internalCount > 0) then
map {
'value' : 'internal',
'label' : lang:get-language-string('internal', $lang),
'frequency' : $internalCount
}
else (),
if($externalCount > 0) then
map {
'value' : 'external',
'label' : lang:get-language-string('external', $lang),
'frequency' : $externalCount
}
else (),
if($noFacsCount > 0) then
map {
'value' : 'without',
'label' : lang:get-language-string('without', $lang),
'frequency' : $noFacsCount
}
else ()
}
};


(:~
: Create facets
:
Expand Down Expand Up @@ -118,7 +157,7 @@ declare %private function facets:display-term($facet as xs:string, $term as xs:s
case 'sex' return
if($term ='Art der Institution') then lang:get-language-string('organisationsInstitutions', $lang)
else lang:get-language-string('sex_' || $term, $lang)
case 'docTypeSubClass' case 'docStatus' case 'textType' return lang:get-language-string($term, $lang)
case 'docTypeSubClass' case 'docStatus' case 'textType' case 'facsimile' return lang:get-language-string($term, $lang)
case 'repository' return facets:display-term-repository($term)
default return str:normalize-space($term)
};
Expand Down
58 changes: 44 additions & 14 deletions modules/search.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace mei="http://www.music-encoding.org/ns/mei";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare namespace exist="http://exist.sourceforge.net/NS/exist";

declare namespace map="http://www.w3.org/2005/xpath-functions/map";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace session="http://exist-db.org/xquery/session";
declare namespace range="http://exist-db.org/xquery/range";
declare namespace ft="http://exist-db.org/xquery/lucene";
import module namespace kwic="http://exist-db.org/xquery/kwic";
import module namespace templates="http://exist-db.org/xquery/templates";
import module namespace functx="http://www.functx.com";
import module namespace core="http://xquery.weber-gesamtausgabe.de/modules/core" at "core.xqm";
import module namespace norm="http://xquery.weber-gesamtausgabe.de/modules/norm" at "norm.xqm";
import module namespace config="http://xquery.weber-gesamtausgabe.de/modules/config" at "config.xqm";
Expand All @@ -19,7 +24,8 @@ import module namespace lang="http://xquery.weber-gesamtausgabe.de/modules/lang"
import module namespace wega-util="http://xquery.weber-gesamtausgabe.de/modules/wega-util" at "wega-util.xqm";
import module namespace controller="http://xquery.weber-gesamtausgabe.de/modules/controller" at "controller.xqm";
import module namespace app="http://xquery.weber-gesamtausgabe.de/modules/app" at "app.xqm";
import module namespace functx="http://www.functx.com";
import module namespace api="http://xquery.weber-gesamtausgabe.de/modules/api" at "api.xqm";


declare variable $search:ERROR := QName("http://xquery.weber-gesamtausgabe.de/modules/search", "Error");

Expand All @@ -34,7 +40,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 @@ -82,7 +88,7 @@ declare
let $result-page-hits-per-entry := map:merge(
for $doc in $subseq
return (
if($doc instance of map() and exists($doc?hits)) then
if($doc instance of map(*) and exists($doc?hits)) then
map:entry($doc?doc/*/data(@xml:id), $doc?hits)
else ()
)
Expand Down Expand Up @@ -200,7 +206,7 @@ declare %private function search:list($model as map(*)) as map(*) {
: Sorting and merging search results
: Helper function for search:search()
~:)
declare %private function search:merge-hits($hits as item()*) as map()* {
declare %private function search:merge-hits($hits as item()*) as map(*)* {
for $hit in $hits
group by $doc := $hit/root()
let $score := sum($hit ! ft:score(.))
Expand All @@ -217,7 +223,7 @@ declare %private function search:merge-hits($hits as item()*) as map()* {
: Do a full text search
: by looking up the appropriate search function in the wdt module
~:)
declare %private function search:fulltext($items as item()*, $searchString as xs:string, $filters as map(), $docType as xs:string) as item()* {
declare %private function search:fulltext($items as item()*, $searchString as xs:string, $filters as map(*), $docType as xs:string) as item()* {
let $query := search:create-lucene-query-element($searchString)
let $search-func := wdt:lookup(., $items)?search
return
Expand Down Expand Up @@ -278,14 +284,26 @@ declare %private function search:additional-mappings($str as xs:string) as eleme

(:~
: Creates a map of to-be-applied-filters from URL request parameters
: Makes use of the `api:validate-*` functions for checking the sanity of parameter values
~:)
declare %private function search:create-filters() as map(*) {
let $params := request:get-parameter-names()[.=$search:valid-params]
let $paramsOrg := request:get-parameter-names()[.=$search:valid-params]
let $params :=
(: "undated" takes precedence over date filter :)
if($paramsOrg[.='undated']) then $paramsOrg[not(.= ('fromDate', 'toDate'))]
else $paramsOrg
let $validate-unknown-param := function-lookup(QName('http://xquery.weber-gesamtausgabe.de/modules/api', 'api:validate-unknown-param'), 1)
return
map:merge(
(: "undated" takes precedence over date filter :)
if($params[.='undated']) then $params[not(.= ('fromDate', 'toDate'))] ! map:entry(., request:get-parameter(., ()))
else $params ! map:entry(., request:get-parameter(., ()))
for $param in $params
let $lookup := function-lookup(QName('http://xquery.weber-gesamtausgabe.de/modules/api', 'api:validate-' || $param), 1)
return
if(exists($lookup)) then $lookup(map:entry($param, request:get-parameter($param, ())))
else if(exists($validate-unknown-param)) then $validate-unknown-param(map:entry($param, request:get-parameter($param, ())))
else (
core:logToFile('warn', 'It seems you did not provide a validate-unknown-param function'),
error($search:ERROR, 'Unknown parameter "' || $param || '". Details should be provided in the system log.')
)
)
};

Expand All @@ -302,6 +320,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 +369,17 @@ 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
for $filter in $filters?facsimile
return
switch($filter)
case 'internal' return $facsimiles[not(@sameAs)][tei:graphic]/root()
case 'external' return $facsimiles[@sameAs]/root()
default return $collection except $facsimiles/root()
};

(:~
:
~:)
Expand Down Expand Up @@ -399,7 +429,7 @@ declare %private function search:get-latest-date($coll as document-node()*, $doc
:
: @return a map with sanitized query string, parameters and recognized dates
~:)
declare %private function search:prepare-search-string($model as map()) as map(*) {
declare %private function search:prepare-search-string($model as map(*)) as map(*) {
let $query-docTypes := request:get-parameter('d', 'all') ! str:sanitize(.)
let $query-string-org := request:get-parameter('q', '')
let $sanitized-query-string := str:normalize-space(str:sanitize(string-join($query-string-org, ' ')))
Expand Down Expand Up @@ -434,7 +464,7 @@ declare %private function search:prepare-search-string($model as map()) as map(*
: @param $callback a callback function to actually do the search if the session is empty
: @return a map object {'filters': {}, 'search-results': {}, 'query-string-org': '', 'query-docTypes': ('') }
~:)
declare %private function search:search-session($model as map(), $callback as function() as map(*)) as map(*) {
declare %private function search:search-session($model as map(*), $callback as function() as map(*)) as map(*) {
let $updatedModel := search:prepare-search-string($model)
let $session-exists :=
try {
Expand All @@ -459,7 +489,7 @@ declare %private function search:search-session($model as map(), $callback as fu

declare
%templates:wrap
function search:get-session-for-singleview($node as node(), $model as map(*)) as map()? {
function search:get-session-for-singleview($node as node(), $model as map(*)) as map(*)? {
let $wegasearch := (:session:get-attribute('wegasearch'):) search:search-session($model, search:search#1)
let $docs := search:normalize-result-entries($wegasearch?search-results)
let $index-of-current-doc := functx:index-of-node($docs, $model?doc)
Expand Down Expand Up @@ -494,7 +524,7 @@ declare %private function search:normalize-result-entries($entries as item()*) a
for $doc in $entries
return
if($doc instance of document-node()) then $doc
else if($doc instance of map()) then $doc?doc
else if($doc instance of map(*)) then $doc?doc
else if($doc instance of element()) then $doc
else if($doc instance of node()) then error($search:ERROR, 'unable to process node: ' || functx:node-kind($doc) || ' ' || name($doc))
else if($doc instance of xs:anyAtomicType) then error($search:ERROR, 'unable to process atomic type: ' || functx:atomic-type($doc))
Expand Down
13 changes: 11 additions & 2 deletions resources/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ $.fn.facets = function ()
limit = 25,
newParams;
//console.log(curParams);
delete curParams.sliderDates.oldFromDate; // delete the property oldFromDate and oldToDate which we don't need for the facets and which is not a valid API parameter
delete curParams.sliderDates.oldToDate;
$(this).each( function(a, b) {
$(b).select2({
closeOnSelect: false,
Expand All @@ -72,6 +74,7 @@ $.fn.facets = function ()
//lang: getLanguage()
},
curParams.facets,
curParams.sliderDates,
{ limit: limit } // need to go after curParams.facets to overwrite the limit setting there
)
return query;
Expand Down Expand Up @@ -720,8 +723,14 @@ function active_facets() {
to=slider.attr('data-to-slider');
min=slider.attr('data-min-slider');
max=slider.attr('data-max-slider');
if(from > min) { params.sliderDates.fromDate = from }
if(to < max) { params.sliderDates.toDate = to }
if(from > min) {
params.sliderDates.fromDate = from;
params.sliderDates.oldFromDate = min;
}
if(to < max) {
params.sliderDates.toDate = to;
params.sliderDates.oldToDate = max;
}
}
/* get values from checkboxes for docTypes at search page
* as well as for other checkboxes on list pages like 'revealed' or 'undated'
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
3 changes: 3 additions & 0 deletions templates/ajax/writings.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h4 data-template="lang:translate">journals</h4>
<h4 data-template="lang:translate">docType</h4>
<select multiple="multiple" data-template="facets:select" name="docTypeSubClass"/>

<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 testing/expected-results/var/Briefe
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
<h4>Bibliothek</h4>
<select multiple="multiple" name="repository" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/repository" data-doc-id="indices" data-doc-type="letters">
<option value="">alle</option></select>
<h4>Faksimile</h4>
<select multiple="multiple" name="facsimile" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/facsimile" data-doc-id="indices" data-doc-type="letters">
<option value="">alle</option></select>
<h4>Dokumentenstatus</h4>
<select multiple="multiple" name="docStatus" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/docStatus" data-doc-id="indices" data-doc-type="letters">
<option value="">alle</option></select>
Expand Down
4 changes: 4 additions & 0 deletions testing/expected-results/var/Dokumente
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@
<select multiple="multiple" name="repository" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/repository" data-doc-id="indices" data-doc-type="documents">
<option value="">alle</option></select>

<h4>Faksimile</h4>
<select multiple="multiple" name="facsimile" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/facsimile" data-doc-id="indices" data-doc-type="documents">
<option value="">alle</option></select>

<h4>Dokumentenstatus</h4>
<select multiple="multiple" name="docStatus" data-api-url="http://localhost:8080/exist/apps/WeGA-WebApp/api/v1/facets/docStatus" data-doc-id="indices" data-doc-type="documents">
<option value="">alle</option></select>
Expand Down
Loading

0 comments on commit 6061bfd

Please sign in to comment.