On this page
Use relevant sorting to only show the most relevant results for a user’s search instead of displaying all the records (exhaustive sorting).
Relevant sorting is only available on Premium plans.
Effect on ranking formula
Algolia’s ranking formula isn’t turned off when you sort by an attribute. Instead, the relevant sorting algorithm selects results as follows:
- Selects results matching the user’s query by using the primary index’s ranking formula.
- Selects only the most relevant results. This a threshold set by the
relevancyStrictnesssetting. With ‘relevancyStrictness`, you instruct the engine to only return results with that relevancy score or better. At query time, the engine computes a relevancy score of 0-100 for each result (by comparing each hit to the best one, a score of 100).
- Sorts the selected results based on the virtual replica’s
- Returns the relevant results.
If multiple results have the same value for a sorting attribute, tie-breaking proceeds as usual on the other defined sorting attributes. For example, suppose you’ve sorted by price and then by popularity. If a query returns three results that cost $99, the engine will then order them by their popularity score.
Relevant sorting considerations
Relevant sorting interacts with other features in ways you might not expect.
Caution: other re-ranking features can affect results
Other re-ranking features such as Rules apply after relevant sorting and will modify sort order. For example, if Personalization promotes expensive items for a particular user based on their past actions, that user might see expensive items at the top of the results, even if they’ve chosen to relevant sort from lowest to highest price.
To ensure predictable behavior, don’t use the following features or parameters with relevant sorting:
When relevant sorting is enabled, the engine still computes facets on all results, not just those defined by the relevant sort. A UI banner detailing the behavior of the relevant sort may help manage the user’s expectations.
Enabling relevant sorting reduces the number of results
Essentially, that’s the point: it gives users more relevant results, not all results (exhaustive sorting).
For example, you search for “chromebook” on an ecommerce site and get Chromebook computers at the top of your results (so far, so good). However, if you then sort by ascending price (because you just want a cheap computer), the top (cheapest) listed items might be “Chromebook power adapters”. Whereas with a relevant sort, you would get fewer results but only see relevant items (computers).
Using a virtual replica even with
relevancyStrictness set to 0 can’t mimic the exhaustive sorting of a standard replica because it doesn’t use the same algorithm. Be aware that a virtual replica:
- Doesn’t duplicate the data. It sorts at query time.
- Can only retrieve a maximum of 20k results, so there’s no guarantee that it will fetch the “deepest” hits.
How to configure relevant sorting
Step one - Create a virtual replica index
If you want to configure relevant sorting, you first need to create a virtual replica index for each attribute you want to sort by.
Virtual replicas provide an alternative “view” of the primary index. Virtual replicas reuse the primary’s ranking formula to return relevant results: for that reason, you can’t change the
ranking on virtual replicas but can use
customRanking to define the sort criteria.
Step two - Connect your UI to your index
Virtual replica indices manage the backend of sorting, but you still need to implement the frontend. You can do this with either custom logic or InstantSearch.
If you’re using InstantSearch, you should use the
sortBy UI widget.
To ensure the user understands how relevant sort works and ensure that they can control their experience:
- Indicate to the user that sorting removed some results
- Offer them the option of displaying more.
You can do this with the
relevantSort UI widget.