Commit 05b18a2a authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

faceted search added

parent ccb33c02
xquery version "3.1";
module namespace fsearch = "http://sade/faceted-search" ;
module namespace fsearch="https://sade.textgrid.de/ns/faceted-search";
import module namespace kwic="http://exist-db.org/xquery/kwic";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace bol="http://blumenbach-online.de/blumenbachiana";
declare namespace templates="http://exist-db.org/xquery/templates";
declare function fsearch:results($node as node(), $model as map(*)) as map()* {
let $page := xs:integer(request:get-parameter("page", "1"))
let $target := config:get("data-dir")
let $hits := local:get-hits($model, $target)
let $obreq := request:get-parameter("order-by", "relevance")
let $order-by := string-join($config:configDoc//module[@key="faceted-search"]//order[@key = $obreq]//xpath , ",")
let $hitsordered :=
if(request:get-parameter("order", "descending") = "descending") then
for $hit in $hits
......@@ -46,7 +41,7 @@ declare function fsearch:results($node as node(), $model as map(*)) as map()* {
declare
function fsearch:searchquery($node as node(), $model as map(*)) {
let $query := request:get-parameter("q", ())
let $query := request:get-parhttp://textgrid.de/ns/SADE/configameter("q", ())
return <input type="text" value="{$query}" name="q" class="form-control" />
};
......@@ -163,8 +158,6 @@ function fsearch:result-id($node as node(), $model as map(*)) {
};
declare function fsearch:facets($model as map(*), $hits) as map() {
let $test := console:log( $config:configDoc )
return
map:new(
for $facet in $config:configDoc//module[@key="faceted-search"]//facet
return
......
......@@ -14,6 +14,7 @@ import module namespace nav="https://sade.textgrid.de/ns/navigation" at "navigat
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
import module namespace app="https://sade.textgrid.de/ns/app" at "app.xqm";
import module namespace multiviewer="https://sade.textgrid.de/ns/multiviewer" at "multiviewer.xqm";
module namespace fsearch="https://sade.textgrid.de/ns/faceted-search" at "faceted-search.xqm";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
......
<?xml version="1.0" encoding="UTF-8"?>
<div data-template="templates:surround" data-template-with="templates/page_index.html" data-template-at="content-container">
<div class="row" data-template="fsearch:results">
<ul class="col-md-3 facet-area"><div data-template="fsearch:facet"/></ul><div class="col-md-9"><div><span id="page" class="hidden" data-template="fsearch:page"/><span id="pages" class="hidden" data-template="fsearch:pages"/><div><ul class="paginator pull-right"/>
Zeige Treffer <span id="hitstart" data-template="fsearch:hitstart"/> -
<span id="hitend" data-template="fsearch:hitend"/> von
<span id="hitcount" data-template="fsearch:hitcount"/> Treffern
</div><form class="form-horizontal" role="form"><div class="form-group"><label class="col-sm-3 control-label">Sortierung nach</label><div class="col-sm-3"><select class="form-control input-sm"><option>Relevanz</option><option>Titel</option><option>Jahr</option></select></div><div class="col-sm-3"><select class="form-control input-sm"><option>Aufsteigend</option><option>Absteigend</option></select></div></div></form><div data-template="templates:each" data-template-from="hits" data-template-to="hit" class="row"><div class="col-md-10"><div data-template="fsearch:result-xslt"/><p data-template="fsearch:result-kwic">KWIC matches</p><a href="#" data-template="fsearch:result-source">Source</a><div data-template="fsearch:result-tble-links"/><hr/></div><div class="col-md-2"><img data-template="fsearch:result-img"/></div></div><div><ul class="paginator pull-right"/>
Zeige Treffer <span id="hitstart" data-template="fsearch:hitstart"/> -
<span id="hitend" data-template="fsearch:hitend"/> von
<span id="hitcount" data-template="fsearch:hitcount"/> Treffern
</div></div></div></div><script>
$(function() {
// http://www.samaxes.com/2011/09/change-url-parameters-with-jquery/
/*
* queryParameters -&gt; handles the query string parameters
* queryString -&gt; the query string without the fist '?' character
* re -&gt; the regular expression
* m -&gt; holds the string matching the regular expression
*/
var queryParameters = {}, queryString = location.search.substring(1),
re = /([^&amp;=]+)=([^&amp;]*)/g, m;
// Creates a map with the query string parameters
while (m = re.exec(queryString)) {
// queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
queryParameters[m[1]] = m[2];
}
$('.paginator').bootstrapPaginator({
bootstrapMajorVersion: 3,
currentPage: $('#page').text(),
totalPages: $('#pages').text(),
pageUrl: function(type, page, current){
queryParameters['page'] = page;
var querystring = "";
$.each(queryParameters, function(key, val) {
querystring += key + "=" + val + "&amp;";
})
querystring = querystring.substring(0, querystring.length-1)
return window.location.pathname + '?' + querystring;
}
})
//$('.paginator').bootstrapPaginator("show", 10);
$('.facet-minus').each(function() {
$(this).html($('&lt;span class="glyphicon glyphicon-minus-sign" /&gt;'));
});
$('.facet-plus').each(function() {
$(this).html($('&lt;span class="glyphicon glyphicon-plus-sign" /&gt;'));
});
});
</script></div>
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