When setting your attributesForFaceting, you can configure each attribute in one of the following ways:
- Not searchable (default): if you want the attribute to be used as a facet
- Searchable: if you want users to be able to search for facet values
- Filter only: if you want the attribute to be used only for filtering (not faceting)
Not Searchable vs Searchable
When an attribute is declared as "not-searchable" or "searchable", it can be used for both faceting and filtering.
The term 'searchable', refers to the ability to search within the facet values themselves, rather than including the facet values as searchable terms when a query is run. This setting is useful for when you want users to be able to search for specific facet values.
For instance, a facet attribute may have thousands of different values making it impossible to display them all in your UI. By setting the facet as searchable, users can look up specific values within that attribute without the need to create a separate index. It means you can still display the most common values first, whilst allowing users to search for more options.
In the example below, category_page_id
has been set as searchable, so users can search for the desired value without having to scroll through all 42 of the attribute's values.
Filtering
When you need to filter on an attribute, such as color
, but don’t need to calculate or display the number of times each color (eg, color:green
, color:blue
etc ) appears in your records, then use filterOnly
.
This setting reduces the index size and improves search speed. You can find more on the difference between filtering and faceting in our docs here.