ranking
Can be used in these methods:
setSettings
set_settings
setSettings
set_settings
setSettings
setSettings
SetSettings
setSettings
SetSettings
setSettings
About this parameter
Controls how Algolia should sort your results.
You must specify a list of ranking criteria for sorting. The tie-breaking algorithm applies each criterion sequentially in the order they’re specified.
Before changing any aspect of these relevance settings, test them in the dashboard. You should also consider planning and implementing A/B testing to ensure that any changes positively affect your results.
Ranking criteria
|
Sort by increasing number of typos. |
|
Sort by increasing geo distance when performing a geo search. This criterion is ignored when not performing a geo search. |
|
Sort by decreasing number of matched query words.
This parameter is useful when you use the |
|
The filter criteria is the sum of scores for filters matched by one hit.
Only one score is considered for OR filters, even if the two filters match.
This parameter must be present in the ranking if you want to use |
|
Sort by increasing proximity of query words in hits. |
|
Sort according to the order of attributes defined by |
|
|
|
|
Modifiers
|
Sort by increasing value of the attribute. |
|
Sort by decreasing value of the attribute. |
Examples
You can either set ranking from the API with the setSettings
method or from the dashboard.
The second and third examples show how to use the API to override Algolia’s default ranking criteria. You can do the same on the dashboard by visiting your index’s Configuration tab, clicking Ranking and Sorting, selecting Expand for the textual ranking criteria, and then dragging the custom ranking to the appropriate location. In the example, that means dragging price
to the top.
You shouldn’t need to change the default criteria since the out-of-the-box ranking works for most use cases.
Set the default ranking
1
2
3
4
5
6
7
8
9
10
11
12
$index->setSettings([
'ranking' => [
'typo',
'geo',
'words',
'filters',
'proximity',
'attribute',
'exact',
'custom'
]
]);
Sort index by an attribute in ascending order (Sort by price in this example)
1
2
3
4
5
6
7
8
9
10
11
12
13
$index->setSettings([
'ranking' => [
'asc(price)',
'typo',
'geo',
'words',
'filters',
'proximity',
'attribute',
'exact',
'custom'
]
]);
Sort index by an attribute in descending order (Sort by price in this example)
1
2
3
4
5
6
7
8
9
10
11
12
13
$index->setSettings([
'ranking' => [
"desc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom"
]
});