Relevant sorting is available on the Build and Premium pricing plans.
To let users select between different rankings in your user interface,
you also need to update your user interface—for example, by including the sort-by widget.
Algolia applies one ranking strategy to each index.
If you want to rank results differently,
like sorting by a specific attribute,
you must create separate replica indices for each type of ranking.
Attribute format
You can only sort by attributes with boolean or numerical values.
Check, that you index numerical attributes as numbers, not strings.
If you want to sort by dates, make sure to represent them as numbers as well.
Configure an attribute for sorting in the Algolia dashboard
On the Configuration tab, go to Relevant sort or Ranking & Sorting.
You’ll see either option, depending on the type of replica you want to configure (virtual or standard).
To add an attribute for sorting, click +Add a sort attribute or +Add sort-by attribute and determine the sort direction (ascending or descending).
Update the ranking parameter of the replica index with the setSettings method.
Example: Relevant sort with a virtual replica
This example configures a Relevant sort with a virtual replica.
The virtual replica reuses the ranking attribute from its primary index,
so you only need to include the customRanking attribute that is used for sorting.
// No initIndexclient.execute{setSettingsof"products_standard_price_desc"`with`IndexSettings(ranking=Some(Seq(Ranking.desc("price"),Ranking.typo,Ranking.geo,Ranking.words,Ranking.filters,Ranking.proximity,Ranking.attribute,Ranking.exact,Ranking.custom)))}