Commit 3611f9a8 authored by Mathias Goebel's avatar Mathias Goebel 🎠

Merge branch 'feature/#100-search-pagination' into 'develop'

Feature/#100 search pagination

Closes #100

See merge request !78
parents 3db840e9 3a82929a
......@@ -76,6 +76,7 @@ declare function app:css-injection($node as node(), $model as map(*), $exist-res
declare function app:javascript-injection($node as node(), $model as map(*), $exist-resource) {
switch ($exist-resource)
case "publish.html" return <script src="~assets/publish-gui/publish-gui.js"/>
case "search.html" return <script src="~assets/faceted-search/bootstrap-paginator.min.js" />
default return ()
};
......
xquery version "3.1";
(:~
: This module takes care of all user interface related matters of searching:
:
: * search
: * display results
: * find and show facets
: * apply filters (from facets)
: * apply sort order
: * pagination
:
: This module needs a working lucene index and is configured in main config.xml.
: It makes use of the template engine and has related template files.
:
: @author Ubbo Veentjer
: @author Mathias Göbel
: @version 1.0
: :)
module namespace fsearch="https://sade.textgrid.de/ns/faceted-search";
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
......@@ -9,6 +26,23 @@ declare namespace cf="https://sade.textgrid.de/ns/configfile";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace templates="http://exist-db.org/xquery/templates";
(:~ Helper for templating, returns the actual search term.
: This method replaces its html node (no %templates-wrap)
:
: Usage: <div>Sie haben nach <strong>
: <span id="prevQuery">
: <span data-template="fsearch:return-query"/>
: </span>
: </strong> gesucht.</div>
:
: Output:
: <div>Sie haben nach <strong>
: <span id="prevQuery">könig</span>
: </strong> gesucht.</div>
:
: @param $node
: @param $model
:)
declare function fsearch:return-query($node as node(), $model as map(*), $q as xs:string?)
as xs:string? {
$q
......@@ -74,12 +108,36 @@ function fsearch:hitend($node as node(), $model as map(*)) {
else $res
};
(:~ Helper for pagination, used from template, returns actal page number.
: This method injects in its HTML node (%templates-wrap).
:
: Usage:
: <span id="page" class="hidden" data-template="fsearch:page"/>
:
: Output:
: <span id="page" class="hidden" data-template="fsearch:page">1</span>
:
: @param $node
: @param $model
:)
declare
%templates:wrap
function fsearch:page($node as node(), $model as map(*)) {
$model("page")
};
(:~ Helper for pagination, used from template, return number of all pages.
: This method injects in its HTML node (%templates-wrap).
:
: Usage:
: <span id="pages" class="hidden" data-template="fsearch:pages"/>
:
: Output:
: <span id="pages" class="hidden" data-template="fsearch:pages">4</span>
:
: @param $node
: @param $model
:)
declare
%templates:wrap
function fsearch:pages($node as node(), $model as map(*)) {
......@@ -348,3 +406,4 @@ declare function local:facetSelected($key as xs:string, $value as xs:string) as
return boolean($r)
};
......@@ -72,17 +72,50 @@
</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; } }) });
<script>
document.addEventListener("DOMContentLoaded", function(event) {
// http://www.samaxes.com/2011/09/change-url-parameters-with-jquery/
/*
* queryParameters: handles the query string parameters
* queryString: the query string without the fist '?' character
* re: the regular expression
* m: holds the string matching the regular expression
*/
var queryParameters = {};
var queryString = location.search.substring(1);
var re = /([^&amp;=]+)=([^&amp;]*)/g, m;
// Creates a map with the query string parameters
while (m = re.exec(queryString)) {
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;
}
})
$('.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>
Markdown is supported
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