-
-
Save AdamSteffanick/6fb9983c7a0d2190a322 to your computer and use it in GitHub Desktop.
facets
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.1"; | |
(: Thanks to Tao You!! :) | |
declare function local:get_facet ($books as element()*, $path as xs:string, $facet_type as xs:string ) as element()? | |
{ | |
<facet type="{$facet_type}">{ | |
for $book in $books | |
let $fld := $book/*[name()=$path] | |
group by $f := $fld | |
order by $f descending | |
return element {$facet_type} {attribute v {$f}, attribute number {fn:count($book)} } | |
}</facet> | |
}; | |
let $csv := fetch:text("https://gist.githubusercontent.com/CliffordAnderson/5be754415308dc407fc9/raw/daa23df71ceef375b83dd5b290284f83beeb710b/books.csv") | |
let $books := csv:parse($csv, map { 'header': true() })/csv/record | |
let $terms := fn:doc("https://gist.githubusercontent.com/CliffordAnderson/ed756303e2cbb63f5fc8/raw/7d20c8b72e4d18bfc5c09baf5c2a8f23491c5a8b/facets.xml") | |
for $term in $terms/terms/term | |
return local:get_facet($books, $term/path/text(), $term/facet/text() ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment