Hi Steve,

We use BaseX to make facets based on EAD control access headings in Archives West, for example: https://archiveswest.orbiscascade.org/search.php?facet=subject:Agriculture

We have XQuery scripts that create custom indexes as BaseX databases called facet-subject, facet-geogname, etc. that look like:

<terms>
  <term text="{subject/geogname/etc. here}">
    <ark>80444/xv12345</ark>
    <ark>80444/xv67890</ark>
  </term>
</terms>

Then when users submit a search, we feed the ARKs of the results to another XQuery that gets the facet terms from those indexes, ordered by count descending. Below $a is the ARKs separated by bars, $n is the facet database names separated by bars, and $m is the maximum number of terms to return per facet.

(: Get facet terms for ARKs from the production indexes :)
declare variable $a as xs:string external;
declare variable $n as xs:string external;
declare variable $m as xs:integer external;
<facets>
{
let $arks := tokenize($a, '\|')
let $names := tokenize($n, '\|')
for $name in $names
  let $facet_db := 'facet-' || $name || '-prod'
  let $sorted_terms := <terms>{
    for $term in db:open($facet_db)/terms/term[ark/text()=$arks]
      group by $text := $term/@text
      let $count := count($term/ark[text()=$arks])
      order by $count descending
      return <term text="{$text}" count="{$count}"/>
  }</terms>
  return <facet type="{$name}">{
    for $term at $index in subsequence($sorted_terms/term, 1, $m)
      return $term
  }</facet>
}
</facets>

Let me know if you'd like more examples, like the XQuery scripts that create the facets from our repository databases in bulk and EADs individually.

-Tamara

On Mon, Jun 6, 2022 at 8:10 AM Majewski, Steven Dennis (sdm7g) <sdm7g@virginia.edu> wrote:

Yes - I mentioned index:facets() in the original post.
I was not clear to me if or how that info could be used for this problem.
Do you have any tips or examples ?

I’m thinking that creating some sort of auxiliary index may be required, and wondering if others have done this and how they chose to do it, or the pros and cons of different approaches: generating an XML mapping to query directly in BaseX vs building an SQL table to query using the BaseX SQL module vs building Solr docs from basex and querying Solr for document lists.

— Steve M.

> On Jun 6, 2022, at 2:59 AM, Kristian Kankainen <kristian@keeleleek.ee> wrote:
>
> Hi,
>
> Did you take a look at the Index module, especially the facet function [1]?
>
> [1]: https://docs.basex.org/wiki/Index_Module#index:facets
>
> Best regards,
> Kristian Kankainen
>
>> On 6. Jun 2022, at 02:12, Liam R. E. Quin <liam@fromoldbooks.org> wrote:
>>
>> On Sun, 2022-06-05 at 21:45 +0000, Majewski, Steven Dennis (sdm7g)
>> wrote:
>>>
>>> Is it possible to do faceted browsing with BaseX ?
>> why wouldn't it be?
>>
>> If you are having performance problems, it may help to maintain a
>> surrogate document in BaseX that just has the facet information, so you
>> don't have to search for it and collate it each time.
>>
>> liam
>>
>> --
>> Liam Quin, https://www.delightfulcomputing.com/
>> Available for XML/Document/Information Architecture/XSLT/
>> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
>> Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org
>



--

Tamara Marnell
Program Manager, Systems
Orbis Cascade Alliance (orbiscascade.org)
Pronouns: she/her/hers