You can change the order of the default criteria but you shouldn’t.
The out-of-the-box ranking order works for most uses.
Before changing this parameter, consider running an A/B test to ensure your changes will positively affect results.
Usage
- Attribute names are case-sensitive.
- Add
asc(attribute)ordesc(attribute)to the list to sort by attributes such aspriceorpopularity. - You can reorder or remove criteria to fine-tune ranking, but the default order works well for most situations.
- Ranking also depends on the order of attributes in
searchableAttributes.
Ranking criteria
Rank results by the fewest spelling mistakes.
Rank results by increasing distance.
This option only applies when performing a geographical search.
Rank results by the number of matching query words, starting with the most matches.
Only applies when using
optionalWords.Rank results by filter score.
This option is essential when using
optionalFilters.Rank results by how close the query words are to each other in the record.
Rank results based on the order of attributes defined in
searchableAttributes.For single-word queries, follows the behavior defined by the
exactOnSingleWordQuery setting.
For multi-word queries, ranks by number of exact word matches.Rank results based on the values of attributes listed in
customRanking.
If not included in ranking, the custom ranking criterion is ignored.Modifiers
Sort in ascending order (lowest to highest).
Sort in descending order (highest to lowest).
Examples
Use the default ranking
Current API clients
Current API clients
var response = await client.SetSettingsAsync(
"INDEX_NAME",
new IndexSettings
{
Ranking = new List<string>
{
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
},
}
);
final response = await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(
ranking: [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
],
),
);
response, err := client.SetSettings(client.NewApiSetSettingsRequest(
"INDEX_NAME",
search.NewEmptyIndexSettings().SetRanking(
[]string{"typo", "geo", "words", "filters", "attribute", "proximity", "exact", "custom"})))
if err != nil {
// handle the eventual error
panic(err)
}
UpdatedAtResponse response = client.setSettings(
"INDEX_NAME",
new IndexSettings().setRanking(Arrays.asList("typo", "geo", "words", "filters", "attribute", "proximity", "exact", "custom"))
);
const response = await client.setSettings({
indexName: 'theIndexName',
indexSettings: { ranking: ['typo', 'geo', 'words', 'filters', 'attribute', 'proximity', 'exact', 'custom'] },
});
var response =
client.setSettings(
indexName = "INDEX_NAME",
indexSettings =
IndexSettings(
ranking =
listOf("typo", "geo", "words", "filters", "attribute", "proximity", "exact", "custom")
),
)
$response = $client->setSettings(
'INDEX_NAME',
['ranking' => [
'typo',
'geo',
'words',
'filters',
'attribute',
'proximity',
'exact',
'custom',
],
],
);
response = client.set_settings(
index_name="INDEX_NAME",
index_settings={
"ranking": [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
],
},
)
response = client.set_settings(
"INDEX_NAME",
Algolia::Search::IndexSettings.new(
ranking: ["typo", "geo", "words", "filters", "attribute", "proximity", "exact", "custom"]
)
)
val response = Await.result(
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(
ranking = Some(Seq("typo", "geo", "words", "filters", "attribute", "proximity", "exact", "custom"))
)
),
Duration(100, "sec")
)
let response = try await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(ranking: [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
])
)
Legacy API clients
Legacy API clients
IndexSettings settings = new IndexSettings();
settings.Ranking = new List
{
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom"
};
index.SetSettings(settings);
res, err := index.SetSettings(search.Settings{
Ranking: opt.Ranking(
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
),
})
index.setSettings(
new IndexSettings().setRanking(Arrays.asList(
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom"
))
);
index
.setSettings({
ranking: [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
],
})
.then(() => {
// done
});
val settings = settings {
ranking {
+Typo
+Geo
+Words
+Filters
+Attribute
+Proximity
+Exact
+Custom
}
}
index.setSettings(settings)
$index->setSettings([
'ranking' => [
'typo',
'geo',
'words',
'filters',
'attribute',
'proximity',
'exact',
'custom'
]
]);
index.set_settings(
{
"ranking": [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom",
]
}
)
index.set_settings(
{
ranking: [
"typo",
"geo",
"words",
"filters",
"attribute",
"proximity",
"exact",
"custom"
]
}
)
client.execute {
setSettings of "myIndex" `with` IndexSettings(
ranking = Some(Seq(
Ranking.typo,
Ranking.geo,
Ranking.words,
Ranking.filters,
Ranking.attribute,
Ranking.proximity,
Ranking.exact,
Ranking.custom
))
)
}
let settings = Settings()
.set(\.ranking, to: [
.typo,
.geo,
.words,
.filters,
.attribute,
.proximity,
.exact,
.custom
])
index.setSettings(settings) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
Sort by ascending price
Current API clients
Current API clients
var response = await client.SetSettingsAsync(
"INDEX_NAME",
new IndexSettings
{
Ranking = new List<string>
{
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
},
}
);
final response = await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(
ranking: [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
],
),
);
response, err := client.SetSettings(client.NewApiSetSettingsRequest(
"INDEX_NAME",
search.NewEmptyIndexSettings().SetRanking(
[]string{"asc(price)", "typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom"})))
if err != nil {
// handle the eventual error
panic(err)
}
UpdatedAtResponse response = client.setSettings(
"INDEX_NAME",
new IndexSettings().setRanking(
Arrays.asList("asc(price)", "typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom")
)
);
const response = await client.setSettings({
indexName: 'theIndexName',
indexSettings: {
ranking: ['asc(price)', 'typo', 'geo', 'words', 'filters', 'proximity', 'attribute', 'exact', 'custom'],
},
});
var response =
client.setSettings(
indexName = "INDEX_NAME",
indexSettings =
IndexSettings(
ranking =
listOf(
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
)
),
)
$response = $client->setSettings(
'INDEX_NAME',
['ranking' => [
'asc(price)',
'typo',
'geo',
'words',
'filters',
'proximity',
'attribute',
'exact',
'custom',
],
],
);
response = client.set_settings(
index_name="INDEX_NAME",
index_settings={
"ranking": [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
],
},
)
response = client.set_settings(
"INDEX_NAME",
Algolia::Search::IndexSettings.new(
ranking: ["asc(price)", "typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom"]
)
)
val response = Await.result(
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(
ranking =
Some(Seq("asc(price)", "typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom"))
)
),
Duration(100, "sec")
)
let response = try await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(ranking: [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
])
)
Legacy API clients
Legacy API clients
IndexSettings settings = new IndexSettings
settings.Ranking = new List
{
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom"
};
index.SetSettings(settings);
res, err := index.SetSettings(search.Settings{
Ranking: opt.Ranking(
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
),
})
index.setSettings(
new IndexSettings().setRanking(Arrays.asList(
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom"
))
);
index
.setSettings({
ranking: [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
],
})
.then(() => {
// done
});
val settings = settings {
ranking {
+Asc("price")
+Typo
+Geo
+Words
+Filters
+Proximity
+Attribute
+Exact
+Custom
}
}
index.setSettings(settings)
$index->setSettings([
'ranking' => [
'asc(price)',
'typo',
'geo',
'words',
'filters',
'proximity',
'attribute',
'exact',
'custom'
]
]);
index.set_settings(
{
"ranking": [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
]
}
)
index.set_settings(
{
ranking: [
"asc(price)",
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom"
]
}
)
client.execute {
setSettings of "myIndex" `with` IndexSettings(
ranking = Some(Seq(
Ranking.asc("price"),
Ranking.typo,
Ranking.geo,
Ranking.words,
Ranking.filters,
Ranking.proximity,
Ranking.attribute,
Ranking.exact,
Ranking.custom
))
)
}
let settings = Settings()
.set(\.ranking, to: [
.asc("price"),
.typo,
.geo,
.words,
.filters,
.proximity,
.attribute,
.exact,
.custom
])
index.setSettings(settings) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}