Facet Option Order
By default, Klevu will return the facet options in a sort order based on the number of records each option has in the result ("Frequency"). An alternative is to list the options in "Alphabetical" order.
Klevu's search API query can be modified to allow for alphabeticaly listing the facet options using "INDEX" as the options.order value.
Modifying the request in this way will apply to all facets.
Parameter Value | Description |
---|---|
FREQ | Sort the options based on the number of corresponding records in the result set |
INDEX | Sort the options alphabetically |
See : Modify Request Overview for more details.
There may be instances where a specific facet can benefit from Alphabetical sorting apart from the frequency default.
The below example will modify a specific facet and sort the filter.options in Alphabetical order for the filter.key "category"
There may be instances when neither Frequency ("FREQ") or Alphabetical ("INDEX") sorting is sufficient.
A common use-case is a facet for Size. A predetermined option sorting for Size can be set for an order in which retail shoppers are accustomed.
This example sets the filter.options to a predetermined order for the filter.key "size".
Important : All available facet options should be included to accommodate variances within the results.
Also, consider case sensitivity as it applies.
This example sets the facet options to a predetermined order for the filter.key "size", but also considers any range of numerical sizes as well.
The following snippet:
- Separates the the alphabetic from the numeric filter option values (based on name)
- Sets the alphabetic object to the defined sort order (optionsOrder).
- Sorts the numeric object to numerical order
- Concatenates the two objects prior to setting to the filter.options
Important : All available facet options should be included to accommodate variances within the results.
Also, consider case sensitivity as it applies.