Faceted Browser
Introduction
The Daisy Wiki includes a faceted browser which allows for faceted navigation through the repository. The faceted browser shows the distinct values for selected properties (facets) of the documents in the repository, and allows to search for documents by selecting values for these facets. This technique is quite common in many websites, but Daisy's faceted browser makes it very easy to add it to your site.
A somewhat bland demo (i.e. only using system properties) of the faceted browser can be found on the main cocoondev.org site.
To use the faceted browser, you need to create a small configuration file in which you list the facets (document properties) to use. You can have multiple faceted navigation configurations.
Howto
Faceted navigations are defined on a per-site level. In the directory for the site, create a subdirectory called "facetednavdefs" if it does not already exist. Thus the location for this directory is:
<wikidata directory>/sites/<sitedir>/facetednavdefs
In this directory, create a file with the extension ".xml", for example "test.xml". The content of the file should be something like this:
<facetedNavigationDefinition xmlns="http://outerx.org/daisy/1.0#facetednavdef">
<options>
<limitToSiteCollection>false</limitToSiteCollection>
<limitToSiteVariant>true</limitToSiteVariant>
<additionalSelects>
<expression>variantLastModified</expression>
<expression>variantLastModifierLogin</expression>
</additionalSelects>
<defaultConditions>true</defaultConditions>
<defaultOrder>documentType ASC, name ASC</defaultOrder>
</options>
<facets>
<facet expression="documentType"/>
<facet expression="collections"/>
<facet expression="lastModifierLogin"/>
</facets>
</facetedNavigationDefinition>
About the content of this file:
The options limitToSiteCollection and limitToSiteVariant speak pretty much for themselves, they define whether the query should automatically limit to documents belonging to the collection, branch and language of the current site. If you want to include the collection or branch/language as facets to search on, then you put the respective options to false, otherwise to true. In this example, since we included collections in the list of facets, we put the limitToSiteCollection option to false.
The <facet> elements list the different facets on which the user can browse. The expression attribute contains an identifier as used in the Daisy Query Language. Thus to include document fields, use $fieldname.
<additionalSelects> is an optional element which adds extra identifiers to the select clause of the query which is sent to the repository. Identifiers are the same ones found in the query language and are set as a list of expression elements. The 'name' and 'summary' identifiers are always the first two identifiers found in the query.
The <defaultConditions> element is optional, and contain a set of a set of query conditions to limit the set of documents on which the faceted navigation will be done, for example:
<defaultConditions>$someField = 'abc' and $someOtherField='def'</defaultConditions>
The <defaultOrder> element is also optional. This element is used to set the default order in which search results will be sorted. The syntax is the same as the order by clause of the query language.
The faceted navigation definition file is validated against an XML Schema, so don't put any additional elements in it or validation will fail.
Once you have saved this file, you can use the faceted browser immediately to browse on the defined facets (a restart of the Daisy Wiki is not needed). The faceted browser is accessed with an URL of this form:
http://localhost:8888/daisy/yoursite/facetedBrowser/test
In which you need to replace "yoursite" with the name of your site and "test" with the name of the file you just created, without the ".xml" extension.
Usage
Faceted browser initialisation
You can define different initialisations for the faceted browser in the faceted navigation definition file. This can be done using an optionsList element.
<facetedNavigationDefinition xmlns="http://outerx.org/daisy/1.0#facetednavdef">
<optionsList defaultOptions="standard">
<options id="standard">
<limitToSiteCollection>false</limitToSiteCollection>
<limitToSiteVariant>true</limitToSiteVariant>
<defaultConditions>true</defaultConditions>
</options>
<options id="doctype">
<limitToSiteCollection>false</limitToSiteCollection>
<limitToSiteVariant>true</limitToSiteVariant>
<defaultConditions>documentType='{request-param:docType|SimpleDocument}'</defaultConditions>
<defaultOrder>documentType ASC</defaultOrder>
</options>
</optionsList>
<facets>
<facet expression="documentType"/>
<facet expression="collections"/>
<facet expression="lastModifierLogin"/>
</facets>
</facetedNavigationDefinition>
If you wish to be able to choose from a range of different options without having to make different definition files you can use optionsList element. It contains a list of different options definitions which must be identified using the id attribute on the options element. In order to know which set of options should be used by default you must set the defaultOptions attribute to the id of one of the options elements.
After having defined your optionsList you will probably want to specify one of the options there. This can be done by adding a request parameter in the url. It would look something like this :
http://localhost:8888/daisy/yoursite/facetedBrowser/test?options=doctype
In the definition you will also find this
{request-param:docType|SimpleDocument} --> {request-param:request-parameter-name|default-request-parameter-value}
If the specified request parameter exists the {...} will be substituted by the parameter value. In case that no such parameter exists the default value will be used. In the url our example will look a bit like this :
http://localhost:8888/daisy/yoursite/facetedBrowser/test?options=doctype&docType=SomeDocumentType
Showing the navigation tree
If you wish to have the navigation tree displayed in the faceted browser you can specify the navigation path as a request parameter (activeNavPath). Here is an example :
http://localhost:8888/daisy/yoursite/facetedBrowser/test?activeNavPath=/path/to/facetedBrowser
The presence of the parameter will convey your wish to see the navigation tree and set the active navigation node to the specified path.
Using an alternative stylesheet
If you wish to use a different stylesheet for the faceted browser than the one found in <skin-dir>/xslt/faceted_browser.xsl, then you can specify this in faceted navigation definition file. Your file might look something like this
<facetedNavigationDefinition xmlns="http://outerx.org/daisy/1.0#facetednavdef"> <stylesheet src="daisyskin:facetednav-styling/myfaceted_browser.xsl"/> <options> ...
Lets follow the example above. First create a directory in your skins directory with the name 'facetednav-styling'. Create a file with the name 'myfaceted_browser.xls' in your freshly created directory. The contents of the file could be something like this
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://outerx.org/daisy/1.0"
xmlns:p="http://outerx.org/daisy/1.0#publisher"
xmlns:n="http://outerx.org/daisy/1.0#navigation"
xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
xmlns:daisyutil="xalan://org.outerj.daisy.frontend.util.XslUtil"
xmlns:urlencoder="xalan://java.net.URLEncoder">
<!-- Import the original stylesheet -->
<xsl:import href="daisyskin:xslt/faceted_browser.xsl"/>
<!-- The customization -->
<xsl:template name="content">
<h1>My own faceted browser</h1>
<div class="facetbrowser-resultcount"><xsl:value-of select="d:facetedQueryResult/d:searchResult/d:resultInfo/@size"/> document(s) found.</div>
<br/>
<xsl:call-template name="options"/>
<br/>
<br/>
<xsl:call-template name="results"/>
<xsl:call-template name="javascript"/>
</xsl:template>
</xsl:stylesheet>
In the simple example above the title on the faceted browser page was changed and the link to query page was removed. See how the original faceted browser styling was used as a base stylesheet. This stylesheet can be found here :
<daisy_home>/daisywiki/webapp/daisy/resources/skins/default/xslt/faceted_browser.xsl
Have a look in there to get an idea of what you can customize.
Defining discrete facets
If you fear that your facet has too many values to be displayed in an fashionable manner you can define discrete facets. These facets will place values in a series of ranges. There are 3 types of discrete facets :
-
STRING
Used for string type values. Words are sampled by the sequence of letters they have in common.
Properties : - This type accepts one property, threshold. This is the minimum amount of values for the facet before values start to be grouped. The amount of groups that will then be available are then maximum threshold+1 .
-
DATE
Used for date type values. The dates are sampled based on the specified spread.
Properties : - threshold (same as above)
- spread. How the ranges are spread out. Ranges are spread out on a logarithmic scale. This property allows specification of the magnitude of the spread. By default this is a magnitude of 1.0 which is a linear spread.
-
NUMBER
Used for number types.
Properties : - threshold (same as above)
- spread (same as above)
When you use the type attribute you tell Daisy that values from this facet
can be discrete.
Here is an example :
<facets>
<!-- A date discrete facet with a parabolic spread. -->
<facet expression="$SomeDate" type="DATE" threshold="7" spread="2.0">
<properties>
<property name="threshold" value="7"/>
<property name="spread" value="2.0"/>
</properties>
</facet>
<!-- Number discrete facet with a linear spread -->
<facet expression="$SomeNumber" type="NUMBER">
<properties>
<property name="threshold" value="7"/>
</properties>
</facet>
<facet expression="$SomeString" type="STRING">
<properties>
<property name="threshold" value="7"/>
</properties>
</facet>
</facets>



There are no comments.