Skip to content

Commit

Permalink
Updates for browse by keywords. #209
Browse files Browse the repository at this point in the history
  • Loading branch information
wsalesky committed Sep 17, 2024
1 parent dc00d31 commit 1bd76cc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
11 changes: 7 additions & 4 deletions cbss/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ <h1>Browse Bibliography by Author</h1>
<!-- Browse Tabs Configurable. -->
<ul class="nav nav-tabs" id="nametabs">
<li>
<a href="browse.html?view=A-Z" default="default">A-Z</a>
<a href="browse.html?view=keywords" default="default">Keyword</a>
</li>
<li>
<a href="browse.html?view=А-Я" default="default">А-Я</a>
<a href="browse.html?view=A-Z">A-Z</a>
</li>
<li>
<a href="browse.html?view=Α-Ω" default="default">Α-Ω</a>
<a href="browse.html?view=А-Я">А-Я</a>
</li>
<li>
<a href="browse.html?view=Ա-Ֆ" default="default">Ա-Ֆ</a>
<a href="browse.html?view=Α-Ω">Α-Ω</a>
</li>
<li>
<a href="browse.html?view=Ա-Ֆ">Ա-Ֆ</a>
</li>
<li>
<a href="browse.html?view=א-ת" default="default">א-ת</a>
Expand Down
11 changes: 10 additions & 1 deletion cbss/facet-def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
<order-by direction="ascending">value</order-by>
</facet-definition>
<!--
<facet-definition name="cbssLang" label="Language">
<group-by function="cbssLanguage">
<sub-path>descendant::tei:relation[@ref="dc:subject"]</sub-path>
</group-by>
<max-values show="5">40</max-values>
<order-by direction="ascending">value</order-by>
</facet-definition>
-->
<!--
<facet-definition name="publicationDate" label="Language of Publication">
<group-by>
<sub-path>descendant::tei:biblStruct/descendant::tei:textLang/@mainLang</sub-path>
Expand All @@ -23,7 +32,7 @@
</facet-definition>
-->
<facet-definition name="cbssKeywords" label="Keywords">
<group-by>
<group-by function="cbssKeywords">
<sub-path>descendant::tei:relation[@ref="dc:subject"]</sub-path>
</group-by>
<max-values show="5">40</max-values>
Expand Down
23 changes: 19 additions & 4 deletions modules/lib/browse.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import module namespace templates="http://exist-db.org/xquery/html-templating";
(: Import Srophe application modules. :)
import module namespace config="http://srophe.org/srophe/config" at "../config.xqm";
import module namespace data="http://srophe.org/srophe/data" at "data.xqm";
import module namespace global="http://srophe.org/srophe/global" at "../lib/global.xqm";
import module namespace tei2html="http://srophe.org/srophe/tei2html" at "../content-negotiation/tei2html.xqm";
import module namespace timeline = "http://srophe.org/srophe/timeline" at "lib/timeline.xqm";
import module namespace slider = "http://srophe.org/srophe/slider" at "../lib/date-slider.xqm";
Expand Down Expand Up @@ -54,6 +55,8 @@ declare function browse:get-all($node as node(), $model as map(*), $collection a
:)
declare function browse:show-hits($node as node(), $model as map(*), $collection, $sort-options as xs:string*, $facets as xs:string?){
let $hits := $model("hits")
let $facet-config := global:facet-definition-file($collection)
let $facetsDisplay := sf:display($model("hits"),$facet-config)
let $rtl :=
if(($browse:lang = 'syr') or ($browse:lang = 'ar')) then 'rtl'
else if(($browse:view = 'ا-ي') or ($browse:view = 'ܐ-ܬ') or ($browse:view = 'א-ת')) then 'rtl'
Expand All @@ -67,6 +70,18 @@ declare function browse:show-hits($node as node(), $model as map(*), $collection
<div class="col-md-12 map-lg" xmlns="http://www.w3.org/1999/xhtml">
{timeline:timeline($hits, 'Timeline', 'tei:teiHeader/tei:publicationStmt/tei:date')}
</div>
else if($browse:view = 'keywords' or $browse:view = '' or not($browse:view)) then
<div class="col-md-12" xmlns="http://www.w3.org/1999/xhtml">
{browse:browse-abc-menu()}
{sf:displayKeywords($model("hits"),$facet-config, $browse:alpha-filter)}
{
if(request:get-parameter('facet-cbssKeywords', '') != '') then
<div>
{browse:display-hits($hits,$collection)}
</div>
else ()
}
</div>
else if($collection = 'bibl') then
<div class="{if($browse:view = 'type' or $browse:view = 'date' or $browse:view = 'facets') then 'col-md-8 col-md-push-4' else 'col-md-12'}" xmlns="http://www.w3.org/1999/xhtml">
{( if(($browse:lang = 'syr') or ($browse:lang = 'ar')) then (attribute dir {"rtl"}) else(),
Expand Down Expand Up @@ -216,22 +231,22 @@ declare function browse:browse-abc-menu(){
<ul class="list-inline">
{
if(($browse:lang = 'syr')) then
for $letter in tokenize('ܐ ܒ ܓ ܕ ܗ ܘ ܙ ܚ ܛ ܝ ܟ ܠ ܡ ܢ ܣ ܥ ܦ ܩ ܪ ܫ ܬ ALL', ' ')
for $letter in tokenize('ܐ ܒ ܓ ܕ ܗ ܘ ܙ ܚ ܛ ܝ ܟ ܠ ܡ ܢ ܣ ܥ ܦ ܩ ܪ ܫ ܬ ', ' ')
return
<li class="syr-menu {if($browse:alpha-filter = $letter) then "selected badge" else()}" lang="syr"><a href="?lang={$browse:lang}&amp;alpha-filter={$letter}{if($browse:view != '') then concat('&amp;view=',$browse:view) else()}{if(request:get-parameter('element', '') != '') then concat('&amp;element=',request:get-parameter('element', '')) else()}">{$letter}</a></li>
else if(($browse:lang = 'ar')) then
for $letter in tokenize('ALL ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي', ' ')
return
<li class="ar-menu {if($browse:alpha-filter = $letter) then "selected badge" else()}" lang="ar"><a href="?lang={$browse:lang}&amp;alpha-filter={$letter}{if($browse:view != '') then concat('&amp;view=',$browse:view) else()}{if(request:get-parameter('element', '') != '') then concat('&amp;element=',request:get-parameter('element', '')) else()}">{$letter}</a></li>
else if($browse:lang = 'ru') then
for $letter in tokenize('А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я ALL',' ')
for $letter in tokenize('А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я ',' ')
return
<li>{if($browse:alpha-filter = $letter) then attribute class {"selected badge"} else()}<a href="?lang={$browse:lang}&amp;alpha-filter={$letter}{if($browse:view != '') then concat('&amp;view=',$browse:view) else()}{if(request:get-parameter('element', '') != '') then concat('&amp;element=',request:get-parameter('element', '')) else()}">{$letter}</a></li>
else
for $letter in tokenize('A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALL', ' ')
for $letter in tokenize('A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ', ' ')
return
<li>{if($browse:alpha-filter = $letter) then attribute class {"selected badge"} else()}
<a href="?lang={$browse:lang}&amp;alpha-filter={$letter}{if(request:get-parameter('element', '') != '') then concat('&amp;element=',request:get-parameter('element', '')) else()}">{$letter}</a></li>
<a href="?lang={$browse:lang}&amp;alpha-filter={$letter}{if($browse:view = 'keywords') then '&amp;view=keywords' else ()}{if(request:get-parameter('element', '') != '') then concat('&amp;element=',request:get-parameter('element', '')) else()}">{$letter}</a></li>
}
</ul>
</div>
Expand Down
47 changes: 46 additions & 1 deletion modules/lib/facets.xql
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,45 @@ declare function sf:display($result as item()*, $facet-definition as item()*) {
else ()
};


(:sf:displayKeywords:)
declare function sf:displayKeywords($result as item()*, $facet-definition as item()*, $sort-option as xs:string*) {
let $facet-definitions :=
if($facet-definition/self::facet:facet-definition) then 'definition'
else $facet-definition/facet:facets/facet:facet-definition[@name='cbssKeywords']
for $facet in $facet-definitions
let $name := string($facet/@name)
let $count := if(request:get-parameter(concat('all-',$name), '') = 'on' ) then () else string($facet/facet:max-values/@show)
let $f := ft:facets($result, $name, ())
let $sortedFacets :=
for $key at $p in map:keys($f)
let $value := map:get($f, $key)
order by $key ascending
return
<facet label="{$key}" value="{$value}"/>
let $sort := if($sort-option != '') then $sort-option else 'A'
let $total := count($sortedFacets)
return
<span class="facet-list">
{(
for $facet at $n in $sortedFacets[matches(@label,concat('^[',$sort,lower-case($sort),']'))]
let $label := string($facet/@label)
let $count := string($facet/@value)
let $param-name := concat('facet-',$name)
let $facet-param := concat($param-name,'=',encode-for-uri($label))
let $active := if(request:get-parameter($param-name, '') = $label) then 'active' else ()
let $url-params :=
if($active) then replace(replace(replace(request:get-query-string(),encode-for-uri($label),''),concat($param-name,'='),''),'&amp;&amp;','&amp;')
else if(request:get-parameter('start', '')) then '&amp;start=1'
else if(request:get-query-string() != '') then concat($facet-param,'&amp;',request:get-query-string())
else $facet-param

return
<a href="search.html?{$url-params}" class="facet-label {$active}" num="{$n}">
{if($active) then (<span class="glyphicon glyphicon-remove facet-remove"></span>)else ()}
{$label} <span class="count"> ({$count})</span> </a>
)}
</span>
};
(:~
: Add generic sort option to facets
: @depreciated
Expand Down Expand Up @@ -750,6 +788,13 @@ return
else 'English'
};

(: CBSS publication place field :)
declare function sf:facet-cbssKeywords($element as item()*, $facet-definition as item(), $name as xs:string){
for $f in $element/descendant::tei:relation[@ref="dc:subject"]
return
normalize-space(string-join($f/descendant::text(),' '))
};


(:
declare function facet:collection($results as item()*, $facet-definition as element(facet:facet-definition)?){
Expand Down

0 comments on commit 1bd76cc

Please sign in to comment.