Algolia’s tie-breaking algorithm
applies the custom ranking attributes in the order they’re listed.
Use asc(attribute) or desc(attribute) to specify the sort direction for each attribute.
To learn more, see Custom ranking .
Usage
Attribute names are case-sensitive.
Records with missing or null values for a custom ranking attribute are considered equal and are placed at the end of the result list, regardless of sort order.
Boolean values are sorted alphabetically: false comes before true in ascending order, and true comes before false in descending order.
Modifiers
Sort by increasing value of the attribute.
Sort by decreasing value of the attribute.
Example
The following example ranks tied records by decreasing popularity.
Records with equal popularity will be ranked by ascending price.
C#
Dart
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var response = await client . SetSettingsAsync (
"INDEX_NAME" ,
new IndexSettings
{
CustomRanking = new List < string > { "desc(popularity)" , "asc(price)" },
}
);
final response = await client. setSettings (
indexName : "INDEX_NAME" ,
indexSettings : IndexSettings (
customRanking : [
"desc(popularity)" ,
"asc(price)" ,
],
),
);
response , err := client . SetSettings ( client . NewApiSetSettingsRequest (
"INDEX_NAME" ,
search . NewEmptyIndexSettings (). SetCustomRanking (
[] string { "desc(popularity)" , "asc(price)" })))
if err != nil {
// handle the eventual error
panic ( err )
}
UpdatedAtResponse response = client . setSettings (
"INDEX_NAME" ,
new IndexSettings (). setCustomRanking ( Arrays . asList ( "desc(popularity)" , "asc(price)" ))
);
const response = await client . setSettings ({
indexName: 'theIndexName' ,
indexSettings: { customRanking: [ 'desc(popularity)' , 'asc(price)' ] },
});
var response =
client. setSettings (
indexName = "INDEX_NAME" ,
indexSettings = IndexSettings (customRanking = listOf ( "desc(popularity)" , "asc(price)" )),
)
$response = $client -> setSettings (
'INDEX_NAME' ,
[ 'customRanking' => [
'desc(popularity)' ,
'asc(price)' ,
],
],
);
response = client.set_settings(
index_name = "INDEX_NAME" ,
index_settings = {
"customRanking" : [
"desc(popularity)" ,
"asc(price)" ,
],
},
)
response = client. set_settings (
"INDEX_NAME" ,
Algolia :: Search :: IndexSettings . new ( custom_ranking: [ "desc(popularity)" , "asc(price)" ])
)
val response = Await .result(
client.setSettings(
indexName = "INDEX_NAME" ,
indexSettings = IndexSettings (
customRanking = Some ( Seq ( "desc(popularity)" , "asc(price)" ))
)
),
Duration ( 100 , "sec" )
)
let response = try await client. setSettings (
indexName : "INDEX_NAME" ,
indexSettings : IndexSettings ( customRanking : [ "desc(popularity)" , "asc(price)" ])
)
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
IndexSettings settings = new IndexSettings ();
settings . CustomRanking = new List
{
"desc(popularity)" ,
"asc(price)"
};
index . SetSettings ( settings );
res , err := index . SetSettings ( search . Settings {
CustomRanking : opt . CustomRanking (
"desc(popularity)" ,
"asc(price)" ,
),
})
index . setSettings (
new IndexSettings (). setCustomRanking ( Arrays . asList (
"desc(popularity)" ,
"asc(price)"
))
);
index
. setSettings ({
customRanking: [ "desc(popularity)" , "asc(price)" ],
})
. then (() => {
// done
});
val settings = settings {
customRanking {
+ Desc ( "popularity" )
+ Asc ( "price" )
}
}
index. setSettings (settings)
$index -> setSettings ([
'customRanking' => [
'desc(popularity)' ,
'asc(price)'
]
]);
index.set_settings({ "customRanking" : [ "desc(popularity)" , "asc(price)" ]})
index. set_settings (
{
customRanking: [
"desc(popularity)" ,
"asc(price)"
]
}
)
client.execute {
setSettings of "myIndex" `with` IndexSettings (
customRanking = Some ( Seq (
CustomRanking .desc( "popularity" ),
CustomRanking .asc( "price" )
))
)
}
let settings = Settings ()
. set (\. customRanking , to : [
. desc ( "popularity" ),
. asc ( "price" )
])
index. setSettings (settings) { result in
if case . success ( let response) = result {
print ( "Response: \( response ) " )
}
}