API Reference / API Parameters / customRanking
Type: list of strings
Engine default: [] (no custom ranking)
Parameter syntax
'customRanking' => [
  'asc(attribute1)',
  'desc(attribute2)'
  ...
]

Can be used in these methods:

About this parameter

Specifies which attributes to assign to Algolia’s custom ranking criterion.

Custom ranking is used to:

  • Define a ranking of results using metrics that are important to you, such as popularity and date.
  • Only show the most relevant results rather than all results: this is called relevant sorting and is implemented with the help of virtual replicas.

Before adding a custom ranking, test the impact in the dashboard. You should also consider planning and implementing A/B testing to ensure that it will positively affect your results.

Usage notes

Specify your custom ranking attributes as a list of strings. Each string must use the syntax: asc(<ATTRIBUTE>) or desc(<ATTRIBUTE>) to determine the ascending or descending sort order.
All custom ranking attributes are applied in the specified sequence by the tie-breaking algorithm.

Modifiers

asc

Sort by increasing value of the attribute.

desc

Sort by decreasing value of the attribute.

Examples

Set a custom ranking

This example uses the setSettings method to apply a custom ranking. It sorts by the decreasing value of the popularity attribute, then if popularity is equal, by the increasing value of the price attribute.

1
2
3
4
5
6
$index->setSettings([
  'customRanking' => [
    'desc(popularity)',
    'asc(price)'
  ]
]);
Did you find this page helpful?