About this parameter
Controls the way results are sorted.
You must specify a list of ranking criteria. Each criterion will be applied in sequence by the tie-breaking algorithm in the order they are specified.
typo: Sort by increasing number of typos.
geo: Sort by decreasing geo distance when performing a geo search. This criterion is ignored when not performing a geo search.
words: Sort by decreasing number of matched query words. This parameter is useful when you use the optionalWords query parameter to rank hits with the most matched words first.
filters: The filter criteria is the sum of scores for filters matched by one hit. In case of OR filters, only one score is taken in account even if the two filters match. This parameter must be present in the ranking if you want to use optionalFilters.
proximity: Sort by increasing proximity of query words in hits.
attribute: Sort according to the order of attributes defined by searchableAttributes.
- If the query contains only one word: The behavior depends on the value of exactOnSingleWordQuery.
- If the query contains multiple words: Sort by decreasing number of words that matched exactly.
- Sort according to a user-defined formula specified via the customRanking setting.
- Note: If
customis not mentioned then you customRanking will not be taken into account.
asc: Sort by increasing value of the attribute.
desc: Sort by decreasing value of the attribute.
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" ] ]);