Before you begin
Declare each attribute used in optional filters in theattributesForFaceting index setting.
Your ranking formula must include the Filters ranking criterion.
To run the code examples on this page, install the latest API client.
Optional filters, replicas, and sorting
On standard replicas, a sort-by attribute takes precedence over optional filters. Optional filters can’t override the order determined by that attribute.Filter scoring
You can add extra nuance to your ranking by specifying scores for different optional filters. For example, you want to display your matching products in the following order:- Apple products first
- Samsung products second
- Huawei products last
Performance
Optional filters are powerful but have some significant performance limitations.-
For attributes that you need for filtering but not faceting, use the
filterOnlymodifier in theattributesForFacetingindex setting. For example: -
Prefer attributes with fewer unique values for optional filters. For example, if
brandhas fewer unique values thanproduct_name, usebrand. - Use as few optional filters as possible. Aim for queries to return a smaller result set.
- Depending on your plan, it may be possible to apply sharding and other custom settings to optimize your implementation. For more information, contact the support team.
For performance reasons,
don’t use filter scoring on searches that may return more than 100,000 results.