How To

Facet Option Order

8min



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.

Frequency vs Alphabetical Option Ordering
Frequency vs Alphabetical Option Ordering




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.

JS


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.



Ordering Options for a Specific Facet

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"

JS

"Category" options sorted alphabetically
"Category" options sorted alphabetically




Predefined Option Ordering

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.

Example 1

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.

JS

Predefined Option Order
Predefined Option Order


Example 2

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.

JS

Example 2
Example 2