|
394 | 394 | expression rooted in the parent node being indexed. In the example the parent will be a <tag>db:article</tag> element, so the context item
|
395 | 395 | for the expression is set to this element.</para>
|
396 | 396 | <para>The expression is evaluated and for each result item, a facet value is added
|
397 |
| - to the dimension using the string value of the item. If the expression returns |
398 |
| - the empty sequence for the current parent node, the corresponding facet will be |
399 |
| - empty as well.</para> |
| 397 | + to the dimension using the string value of the item. Therefore if the expression |
| 398 | + returns multiple items, a facet for that dimension will also hold multiple values. |
| 399 | + If the expression returns the empty sequence for the current parent node, the corresponding |
| 400 | + facet will be empty as well.</para> |
400 | 401 | <para>A facet can also be defined to be hierarchical. A typical example would be a date, which consists of a year, month and day component. By
|
401 | 402 | indexing the single components as separate parts of a hierarchical facet, we enable the user to drill down by year first, then by month and
|
402 | 403 | finally by day. Let's assume each of our docbook articles has a <tag>pubdate</tag> containing a date in <code>xs:date</code>
|
403 | 404 | format:</para>
|
404 | 405 | <programlisting language="xml" xlink:href="listings/listing-52.txt"></programlisting>
|
| 406 | + <para>Hierarchical facets may also hold multiple values, for example if we would like to associate |
| 407 | + our documents with a subject classification on various levels of granularity (say: <emphasis>science</emphasis> with |
| 408 | + <emphasis>math</emphasis> and <emphasis>physics</emphasis> as subcategories or <emphasis>humanities</emphasis> with |
| 409 | + <emphasis>art</emphasis>, <emphasis>sociology</emphasis> and <emphasis>history</emphasis>). |
| 410 | + This way we enable the user to drill down into broad <emphasis>humanities</emphasis> |
| 411 | + or <emphasis>science</emphasis> subject first and choose particular topics afterwards. |
| 412 | + If the result of the hierarchical facet <code>expression</code> |
| 413 | + evaluates to an array, each of array members will be treated as a hierarchical value for that facet. |
| 414 | + Such an array could look in XQuery similar to <code>[('science', 'math'), ('humanities', 'history')]</code> and be |
| 415 | + a result of evaluationg a function like <code>idx:subject-hierarchy</code> below stored in an imported module (see <link linkend="external-module">below</link>) |
| 416 | + </para> |
| 417 | + <programlisting language="xml" xlink:href="listings/listing-520.xml"/> |
| 418 | + <programlisting language="xquery" xlink:href="listings/listing-521.txt"/> |
| 419 | + <para>which assumes hierarchical subject structure stored in <emphasis>/db/lucenetest/subjects.xml</emphasis></para> |
| 420 | + <programlisting language="xml" xlink:href="listings/listing-522.xml"/> |
405 | 421 | <para>Next, we may want to define fields for the authors and title of the article. In docbook, <tag>author</tag> can be a complex element,
|
406 | 422 | consisting e.g. of a <tag>personname</tag> with nested
|
407 | 423 | <tag>surname</tag> and <tag>firstname</tag>. For display to the user and sorting we want to pre-compute a normalized string out of those
|
|
0 commit comments