Skip to content

Commit 46040b8

Browse files
committed
(feature) detailed explanation of refining queries with facets
particularly explaining nuances of hierarchical facets and multiple values
1 parent 85404a1 commit 46040b8

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let $options := map {
2+
"facets": map {
3+
"keyword": ("indexing", "facets"),
4+
"date": [("2018", "06"), ("2018", "05")]
5+
}
6+
}
7+
return
8+
collection("/db/articles")//db:article[ft:query(., "xml", $options)]

src/main/xar-resources/data/lucene/lucene.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,23 @@
561561
dimension and value, pass a key "facets" in the options map given in the third
562562
parameter of <literal>ft:query</literal>:</para>
563563
<programlisting language="xquery" xlink:href="listings/listing-57.txt"/>
564-
<para>If you specify more than one value for one facet dimension, these will be linked
565-
together with a logical <literal>or</literal>, thus returning elements matching any
566-
of the alternative facet values for that dimension. If you specify multiple
567-
dimensions, they are treated as an <literal>and</literal>, limiting the result to
568-
elements matching both dimensions.</para>
564+
<para>If you specify multiple dimensions, these will be linked together with a logical
565+
<literal>and</literal>, limiting the result to elements matching both dimensions.</para>
566+
<para>Treatment of multiple values for one facet dimension depends on the type of facet.
567+
For non-hierarchical facets, as in example above, if you specify more than one value these
568+
will be linked together with a logical <literal>or</literal>,
569+
returning elements matching any of the alternative facet values for that dimension.</para>
570+
<para>In case of hierarchical facets, a sequence of items is
571+
interpreted as a hierarchical value/subvalue facet path, therefore expression like
572+
<code>("2018", "06", "25")</code> for the <emphasis>date</emphasis> dimension mentioned
573+
earlier will return nodes from the 25th of June 2018. Nested sequences
574+
are not allowed in XQuery, so the only way to pass in multiple hierarchical facet paths
575+
is by wrapping the whole structure in an array. Each array element then is logically
576+
linked with its other members with <literal>or</literal> expression. To query
577+
for elements from June <emphasis>or</emphasis> May 2018 we therefore need to specify
578+
date dimension values as <code>[("2018", "06"), ("2018", "05")]</code>
579+
</para>
580+
<programlisting language="xquery" xlink:href="listings/listing-571.txt"/>
569581
</sect2>
570582
<sect2 xml:id="describe">
571583
<title>Describing Queries in XML</title>

0 commit comments

Comments
 (0)