API Reference / API Parameters / customRanking
Jan. 07, 2019

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 the custom ranking criterion.

Each string must conform to the syntax asc(${attributeName}) or desc(${attributeName}) and specifies a (respectively) increasing or decreasing sort on an attribute. All sorts are applied in sequence by the tie-breaking algorithm in the order they are specified.

Modifiers:

  • asc: Sort by increasing value of the attribute.

  • desc: Sort by decreasing value of the attribute.

Examples

Set a custom ranking

In this example we will sort by decreasing value of the popularity attribute, then in case of equality by 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?