Commit dbe56cf8 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

facets enabled

parent 2daa80bd
......@@ -9,7 +9,7 @@
<param key="textgrid.webauth">https://textgridlab.org/1.0/WebAuthN/TextGrid-WebAuth.php</param>
<param key="textgrid.authZinstance">textgrid-esx2.gwdg.de</param>
<param key="textgrid.public-triplestore">https://textgridlab.org/1.0/triplestore/textgrid-public</param>
<param key="textgrid.nonpublic-triplestore">https://textgridlab.org/1.0/triplestore/textgrid-nonpublic</param>
<param key="textgrid.nonpublic-triplestore"></param>
<!-- if you want to distinguish between develop and productive instance,
set sade.develop "true"
......@@ -79,7 +79,7 @@
</param>
<param key="thumbnail">false</param>
<param key="facets">
<facet key="persons" title="Person">
<facet key="authors" title="Authors">
<xpath>tei:author</xpath>
</facet>
<facet key="keywords" title="Schlagwort">
......
......@@ -47,7 +47,9 @@ declare function config:get($key as xs:string){
: @param $module-key – the name of the module
: :)
declare function config:get($key as xs:string, $module-key as xs:string?) {
$config:file/cf:config/cf:module[@key = $module-key]/cf:param[@key = $key]/node()
let $base := $config:file/cf:config/cf:module[@key = $module-key]/cf:param[@key = $key]
let $elements := $base/*
return if($elements) then $elements else $base/node()
};
(:~
......
xquery version "3.1";
module namespace fsearch="https://sade.textgrid.de/ns/faceted-search";
import module namespace kwic="http://exist-db.org/xquery/kwic";
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace kwic="http://exist-db.org/xquery/kwic";
declare namespace bol="http://blumenbach-online.de/blumenbachiana";
declare namespace cf="https://sade.textgrid.de/ns/configfile";
......@@ -14,19 +13,17 @@ declare function fsearch:results($node as node(), $model as map(*)) as map()* {
let $page := xs:integer(request:get-parameter("page", "1"))
let $target := $config:app-root || "/" || config:get("project-id") || "/data"
let $hits := local:get-hits($model, $target)
let $console := console:log( $hits )
let $obreq := request:get-parameter("order-by", "relevance")
(: let $order-by := string-join($config:configDoc//module[@key="faceted-search"]//order[@key = $obreq]//xpath , ","):)
let $order-by := ""
let $hitsordered :=
if(request:get-parameter("order", "descending") = "descending") then
for $hit in $hits
order by util:eval($order-by) descending
(: order by util:eval($order-by) descending:)
return $hit
else
for $hit in $hits
order by util:eval($order-by) ascending
(: order by util:eval($order-by) ascending:)
return $hit
let $num := try{ xs:integer(config:get("hits-per-page", "faceted-search")) } catch * {0}
......@@ -167,9 +164,9 @@ function fsearch:result-id($node as node(), $model as map(*)) {
declare function fsearch:facets($model as map(*), $hits) as map() {
map:new(
for $facet in config:get("facets", "faceted-search")//cf:facet
for $facet in config:get("facets", "faceted-search")
return
map:entry(xs:string($facet/@key), local:facet($model, $hits, $facet/@key, $facet//cf:xpath/text()))
map:entry($facet/string(@key), local:facet($model, $hits, $facet/string(@key), string($facet/cf:xpath/text())))
)
};
......@@ -183,11 +180,10 @@ function fsearch:facet-title($node as node(), $model as map(*)) {
};
declare function fsearch:facet($node as node(), $model as map(*)) as item()* {
let $facets := config:get("facets", "faceted-search")//cf:facet
for $facet in $facets
let $facets := config:get("facets", "faceted-search")
for $facet in $facets
(: hide facet-categories with less than one entry :)
where (count($model("facets")(xs:string($facet/@key))) > 0)
where (count($model("facets")($facet/string(@key))) > 0)
return
<li><strong>{xs:string($facet/@title)}</strong>
<ul class="hideMore">{local:deselected-for-key($model, xs:string($facet/@key))}{$model("facets")(xs:string($facet/@key))}</ul>
......@@ -273,26 +269,22 @@ declare function local:get-hits($model as map(*), $target as xs:string) as node(
let $query := request:get-parameter("q", ())
let $fxquery := local:construct-facet-query($model)
let $console := console:log( $fxquery )
let $options :=
<options>
<leading-wildcard>yes</leading-wildcard>
</options>
let $console := console:log( config:get("query-root", "faceted-search") )
let $xqueries :=
for $query-root in config:get("query-root", "faceted-search")
return
if($query) then
"collection($target)" || $query-root || $fxquery || "[ft:query(., $query, $options)]"
else
"collection($target)" || $query-root || $fxquery
for $query-root in config:get("query-root", "faceted-search")
return
if($query) then
"collection($target)" || $query-root || $fxquery || "[ft:query(., $query, $options)]"
else
"collection($target)" || $query-root || $fxquery
let $xquery := string-join($xqueries, " | ")
let $console := console:log( $xquery )
return util:eval($xquery)
};
declare function local:construct-facet-query($model as map(*)) as xs:string {
......
<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns="http://exist-db.org/collection-config/1.0">
<!-- when you going to edit here, keep in mind that this file is stored in the
......@@ -13,6 +12,7 @@
</analyzer>
<!-- text qname="tei:TEI"/ -->
<text qname="tei:TEI" analyzer="fontane"/>
<text qname="tei:text" analyzer="fontane"/>
<text qname="tei:surface" analyzer="fontane">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment