Configure Sorting and Limiting of Facet Values
Overview
This page describes how to configure sorting and limiting of facet values in a faceted navigation tree.
When to Use
Configure sorting and limiting of facet values when you need to control the order and number of values displayed for a facet. Typical scenarios include:
- Sorting a date facet by year in descending order.
- Displaying only the top N most-used tags in a tag cloud.
Note: This page covers sorting and limiting facet values. To configure sorting and limiting of result sets in a faceted tree, see Configure Sorting and Limiting of Result Sets.
Configuration
You configure the ordering and limit of facet values per facet using the hippofacnav:facetnodenames property in a faceted tree configuration.
The following parameters are available:
sortby(String): Determines the sorting field. Options:count: Sorts by result count. Descending is the default, except for ranges.facetvalue: Sorts by the facet value itself.config: For configured ranges. The default order is ascending, matching the configuration order.
sortorder(String): Specifies the sort direction. Options:descending,ascending.limit(int): Sets the maximum number of unique facet values to display. This is useful for tag clouds or when there are many unique facet values.
Sorting by facetvalue supports Long, Double, Date, and String types. At runtime, the system determines whether the values are numerical or strings.
Examples
Sort by Facet Value
To sort brands by name for product documents with a myproject:brand property, configure the facet as follows:
/content/documents/myproject: /faceted-products: jcr:primaryType: hippofacnav:facetnavigation hippo:docbase: d2b1775c-fb97-4080-bd66-ede4ac874b5a hippofacnav:facets: [ myproject:brand ] hippofacnav:facetnodenames: [ 'Brand${sortby:"facetvalue", sortorder:"ascending"}' ]
Limit the Number of Facet Values
To display only the top 25 brands when there are thousands of unique brands, add a limit parameter:
/content/documents/myproject: /faceted-products: jcr:primaryType: hippofacnav:facetnavigation hippo:docbase: d2b1775c-fb97-4080-bd66-ede4ac874b5a hippofacnav:facets: [ myproject:brand ] hippofacnav:facetnodenames: [ 'Brand${sortby:"facetvalue", sortorder:"ascending", limit:25}' ]
Sort by Configured Ranges
If you configure facet value ranges for myproject:brand, you can sort the facet values by the configured range names:
/content/documents/myproject: /faceted-products: jcr:primaryType: hippofacnav:facetnavigation hippo:docbase: d2b1775c-fb97-4080-bd66-ede4ac874b5a hippofacnav:facets: [ "myproject:brand$[{name:'all', resolution:'string'},\ \ {name:'a f', resolution:'string', lower:'a', upper:'g'},\ \ {name:'g m', resolution:'string', lower:'g', upper:'n'},\ \ {name:'n z', resolution:'string', lower:'n', upper:'{'}]" ] hippofacnav:facetnodenames: [ 'Brand${sortby:"config", sortorder:"descending"}' ]