Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facets: sort by output and add output to combobox #208

Merged
merged 5 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading