Step 2: Configure Fields for Faceting
Set as Searchable Field
While facets are primarily a frontend feature and you configure how to display facets, you first need to pass facet data from the backend to the frontend. To do this, set the fields you want to enable facets for as searchable fields with type facet for each vertical.
Check out the Add Facets to a Search Vertical help article for step-by-step instructions on how to do this.
Review the Facets and Filters unit for a refresher on facets.
Set Ranges
To add the additional set up to the Search configuration for numerical facets, you’ll have to edit the JSON directly as this is not supported in the UI.
- Click Search in the navigation bar and click on the desired Search experience.
- Click Edit in JSON to navigate to your Search Configuration file.
- In the relevant vertical, add the
facets
object with afields
array. - For each field you want to add a numerical facet for, add an object with the following fields:
fieldId
: The field API name (see the View Field API Name (Content) help article for how to find this).sortCriteria
: How to sort the field. Options are”ASC”
or”DESC”
. If not specified, the default is ASC.ranges
: One of three options to configure numerical facet ranges. See below.
- Click Save.
No Configuration Set
If a number field is set as a facet in searchableFields
or facets
, but no facets
config object is provided, the field will be set up as a dynamic range with four buckets. This is added on the next save.
Option 1: Explicitly Set Ranges
Explicitly set ranges that will not change when the results set changes. Static ranges with a result count of 0 are not returned. Also note that the display names will not be internationalized.
"facets": {
"fields": [
{
"fieldId": "price",
"sortCriteria": "ASC",
"ranges": [
{
"start": 0,
"end": 70,
"displayName": "Up to $70"
},
{
"start": 70,
"end": 100,
"displayName": "$70 - $100"
},
{
"start": 100,
"displayName": "Over $100"
}
]
}
]
}
ranges
takes an array of objects with the following properties:
start
: The start of the range (inclusive). If not specified, the range is unbounded.end
: The end of the range (inclusive). If not specified, the range is unbounded.displayName
: The label for this facet option. If not specified, this defaults to"[start] - [end]"
"> [start]"
if end is not specified"< [end]"
if start is not specified
Option 2: Dynamic Range Generated by the Backend
Setting the algorithm
property as ”DYNAMIC”
will distribute all the entities (not just the ones returned for that search) roughly evenly across the maximum number of buckets specified by bucketCount
. If not specified, bucketCount
defaults to 4.
"facets": {
"fields": [
{
"fieldId": "price",
"sortCriteria": "ASC",
"ranges": {
"algorithm": "DYNAMIC",
"bucketCount": 3
}
}
]
}
The above configuration may give the following buckets (results count in parentheses):
- 0 - 23 (20)
- 23 - 60 (20)
- 60 - 120 (20)
Option 3: Static Range Generated by the Backend
Setting the algorithm
property as ”STATIC”
will create buckets of length specified by bucketLength
(required).
"facets": {
"fields": [
{
"fieldId": "price",
"sortCriteria": "ASC",
"ranges": {
"algorithm": "STATIC",
"bucketLength": 24
}
}
]
}
With the same set of data as the dynamic ranges example, the above configuration may give different buckets (results count in parentheses):
- 0 - 24 (19)
- 24 - 48 (10)
- 48 - 72 (12)
- 72 - 96 (14)
- 96 - 120 (5)