Commit 5b68c904 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

added first version of faceted search

parent 3f556d65
......@@ -52,27 +52,28 @@
<param key="viewer-html">index.html?id=/xml/data/</param>
<!-- how much kwic hits to show per document -->
<param key="kwic-hits">3</param>
<param key="kwic-width">20</param>
<param key="thumbnail">false</param>
<param key="hits-per-page">10</param>
<param key="result-xslt">/db/sade-projects/textgrid/xslt/search-hit.xslt</param>
<param key="result-xslt">search-hits.xslt</param>
<param key="query-root">
<xpath>//tei:TEI</xpath>
<xpath xmlns="">//tei:TEI</xpath>
</param>
<param key="result-title">
<xpath>//tei:fileDesc//tei:titleStmt/tei:title/text()</xpath>
<xpath xmlns="">//tei:fileDesc//tei:titleStmt/tei:title/text()</xpath>
</param>
<param key="thumbnail">false</param>
<param key="facets">
<facet key="persons" title="Person">
<facet key="persons" title="Person" xmlns="">
<xpath>tei:author</xpath>
</facet>
<facet key="keywords" title="Schlagwort">
<facet key="keywords" title="Schlagwort" xmlns="">
<xpath>tei:term</xpath>
</facet>
<facet key="dates" title="Zeit">
<facet key="dates" title="Zeit" xmlns="">
<xpath>tei:date/@when</xpath>
</facet>
<facet key="places" title="Publikationsort">
<facet key="places" title="Publikationsort" xmlns="">
<xpath>tei:pubPlace</xpath>
</facet>
</param>
......
......@@ -3,15 +3,19 @@ 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";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace bol="http://blumenbach-online.de/blumenbachiana";
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";
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 $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 := ""
......@@ -97,7 +101,7 @@ declare function fsearch:result-xslt($node as node(), $model as map(*)) {
let $docname := util:document-name($model("hit"))
let $id := substring-before($docname, ".")
let $link := config:get('viewer-html','faceted-search') || $docname
let $xslt := config:get('result-xslt','faceted-search')
let $xslt := $config:app-root || "/" || config:get('result-xslt','faceted-search')
let $docpath := config:get("data-dir") || "/xml/data/" || $docname
let $title := doc($docpath)//tei:fileDesc/tei:titleStmt/tei:title
......@@ -118,17 +122,20 @@ declare function fsearch:result-score($node as node(), $model as map(*)) {
};
declare function fsearch:result-img($node as node(), $model as map(*)) {
(: TODO: could better be done in template, than by param :)
if(xs:boolean(config:get( "thumbnail","faceted-search"))) then
(: TODO image-xpath should be configured by conf.xml:)
let $src := $model("hit")//bol:kerndaten/bol:mediafiles//bol:mediafile[1]/@file_uri || ($model("hit")//tei:pb)[1]/@facs
return
if(string-length($src) > 0) then
<img src="{config:get("digilib.url")}{$src}{config:get("digilib.thumbnailparam")}"/>
else
()
else
()
()
(: (: TODO: could better be done in template, than by param :):)
(: if(xs:boolean(config:get( "thumbnail","faceted-search"))) then:)
(: (: TODO image-xpath should be configured by conf.xml:):)
(: let $src := $model("hit")//bol:kerndaten/bol:mediafiles//bol:mediafile[1]/@file_uri || ($model("hit")//tei:pb)[1]/@facs:)
(: return:)
(: if(string-length($src) > 0) then:)
(: <img src="{config:get("digilib.url")}{$src}{config:get("digilib.thumbnailparam")}"/>:)
(: else:)
(: ():)
(: else:)
(: ():)
};
declare function fsearch:result-kwic($node as node(), $model as map(*)) {
......@@ -140,8 +147,8 @@ declare function fsearch:result-kwic($node as node(), $model as map(*)) {
return
for $i in 1 to xs:integer(config:get("kwic-hits", "faceted-search"))
return
if(($expanded//exist:match)[$i]) then
kwic:get-summary($expanded, ($expanded//exist:match)[$i], <config width="{$kwic-width}"/>)
if(($expanded//exist:match)[$i]) then ()
(: kwic:get-summary($expanded, ($expanded//exist:match)[$i], <config width="{$kwic-width}"/>):)
else ()
};
......@@ -266,13 +273,15 @@ 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 $xqueries := for $query-root in config:get("query-root", "faceted-search")//xpath
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)]"
......@@ -280,6 +289,8 @@ declare function local:get-hits($model as map(*), $target as xs:string) as node(
"collection($target)" || $query-root || $fxquery
let $xquery := string-join($xqueries, " | ")
let $console := console:log( $xquery )
return util:eval($xquery)
};
......
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" indent="no"/>
<xsl:param name="id"/>
<xsl:param name="link"/>
<xsl:template match="/">
<div>
<strong>
<a href="{$link}">
<xsl:value-of select="//tei:fileDesc/tei:titleStmt/tei:title"/>
</a>
</strong>
<p>
/ <xsl:value-of select="//tei:author"/>.
- <xsl:value-of select="//tei:sourceDesc/tei:biblFull/tei:publicationStmt/tei:pubPlace"/>
: <xsl:value-of select="//tei:sourceDesc/tei:biblFull/tei:publicationStmt/tei:date/@when"/>. <br/>
<a href="#" onclick="return false;" data-toggle="collapse" data-target="#meta2_{$id}">
mehr <span class="glyphicon glyphicon-collapse-down"/>
</a>
</p>
<p id="meta2_{$id}" class="collapse">
<xsl:value-of select="//tei:notesStmt/tei:note"/>
</p>
</div>
</xsl:template>
</xsl:stylesheet>
<?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"/>
<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"/>
</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>
</div>
</div>
</div>
</div>
<script>
$(function() {
// http://www.samaxes.com/2011/09/change-url-parameters-with-jquery/
......@@ -57,4 +100,5 @@
});
});
</script></div>
</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