Last active
August 29, 2015 14:02
-
-
Save wsalesky/7279300fb07b39e9edfa to your computer and use it in GitHub Desktop.
Facets POC using group by rather then index-keys(). No bells or whistles but you can get the general idea.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
declare namespace xqi="http://xqueryinstitute.org/ns"; | |
(:~ | |
: Adds facets for speakers | |
: @param $hits passed from search function | |
: :) | |
declare function local:facet-speaker($hits as element()*) as element()*{ | |
for $speakers in $hits | |
group by $speaker := $speakers/tei:speaker/text() | |
order by count($speakers) descending | |
return | |
<div count="{count($speakers)}">{$speaker}</div> | |
}; | |
(:~ | |
: Adds facets for Titles | |
: @param $hits passed from search function | |
: :) | |
declare function local:facet-title($hits as element()*) as element()*{ | |
for $titles in $hits | |
group by $title := $titles/ancestor::tei:TEI//tei:titleStmt/tei:title/text() | |
order by count($titles) descending | |
return | |
<div count="{count($titles)}">{$title}</div> | |
}; | |
(:~ | |
: Adds facets for genres | |
: @param $hits passed from search function | |
: :) | |
declare function local:facet-genre($hits as element()*)as element()*{ | |
for $genres in $hits | |
group by $genre := $genres/ancestor::tei:TEI//xqi:genre/text() | |
return | |
<div count="{count($genres)}">{$genre}</div> | |
}; | |
let $hits := collection('/db/apps/xq-institute/data/indexed-plays')//tei:sp[ft:query(.,'pox')] | |
return | |
<div> | |
<div class="title"> | |
{local:facet-title($hits)} | |
</div> | |
<div class="speaker"> | |
{local:facet-speaker($hits)} | |
</div> | |
<div class="speaker"> | |
{local:facet-genre($hits)} | |
</div> | |
<div class="results"> | |
{ | |
for $hit in $hits | |
return | |
<div class="result"> | |
{$hit} | |
</div> | |
}</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment