Skip to content

Commit

Permalink
Merge pull request #208 from eeditiones/sort-facets
Browse files Browse the repository at this point in the history
Facets: sort by output and add output to combobox
  • Loading branch information
wolfgangmm authored Dec 31, 2023
2 parents 8af9e4f + 8cf025d commit 9727210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ declare variable $config:facets := [
"dimension": "feature",
"heading": "facets.feature",
"source": "api/search/facets/feature",
"output": function($label) {
upper-case(substring($label,1,1)) || substring($label, 2)
},
"max": 5,
"hierarchical": false()
},
Expand Down
7 changes: 4 additions & 3 deletions modules/facets.xql
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import module namespace config="http://www.tei-c.org/tei-simple/config" at "conf

declare namespace tei="http://www.tei-c.org/ns/1.0";

declare function facets:sort($facets as map(*)?) {
declare function facets:sort($config as map(*), $facets as map(*)?) {
array {
if (exists($facets)) then
for $key in map:keys($facets)
let $value := map:get($facets, $key)
order by $key ascending
let $sortKey := if (exists($config?output)) then $config?output($key) else $key
order by $sortKey ascending
return
map { $key: $value }
else
Expand All @@ -49,7 +50,7 @@ declare function facets:print-table($config as map(*), $nodes as element()+, $va
if (map:size($facets) > 0) then
<table>
{
array:for-each(facets:sort($facets), function($entry) {
array:for-each(facets:sort($config, $facets), function($entry) {
map:for-each($entry, function($label, $freq) {
let $content := facets:translate($config, $lang, $label)
return
Expand Down
1 change: 0 additions & 1 deletion modules/lib/api/search.xql
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ declare function sapi:list-facets($request as map(*)) {
})
let $hits := session:get-attribute($config:session-prefix || ".hits")
let $facets := ft:facets($hits, $type, ())

let $matches :=
for $key in if (exists($request?parameters?value)) then $request?parameters?value else map:keys($facets)
let $label := facets:translate($facetConfig, $lang, $key)
Expand Down

0 comments on commit 9727210

Please sign in to comment.