- Create a replica index
- Configure an attribute for sorting
- Update your user interface
Replica indices
Think of a replica index as a duplicate of your primary index but with a different sorting of results. Choose from two types of replicas: standard or virtual:- Use a standard replica for exhaustive sorting. This method sorts results by the chosen attribute.
- Use a virtual replica for relevant sorting. This method prioritizes relevant results while still incorporating the sorting preference for the chosen attribute.
Configure an attribute for sorting in the Algolia dashboard
Only sort indices by numeric or boolean attributes. With string attributes, the sort order isn’t guaranteed. If you want to sort an index alphabetically, usecustomRanking
instead.
- Create a replica index.
- Refresh the dashboard page in your browser.
- Select the replica index.
- On the Configuration tab, go to Relevant sort or Ranking and Sorting. You’ll see either option, depending on the type of replica you want to configure (virtual or standard).
- Click +Add a sort attribute or +Add sort-by attribute
- Type in the name of the attribute you want to sort. Be careful here: Algolia doesn’t check to see if what you type matches the name of an attribute in the index.
- Determine the sort direction (Ascending or Descending).
- Review and save your changes.
Configure an attribute for sorting with the API
- Create a replica index.
- Update the
ranking
parameter of the replica index with thesetSettings
method.
Update user interface
To let users select between different rankings in your user interface, you also need to update it—for example, by providing asort-by
widget.
Example: relevant sort by price
This example applies relevant sorting to a virtual replica.For virtual replicas, you only need to include the
customRanking
attribute used for sorting: price
.Example: exhaustive sort by price
This example applies exhaustive sorting to a standard replica.For standard replicas, you need to provide all ranking attributes.