Ranking rules
Child route of the settings route.
Ranking rules are built-in rules that ensure relevancy in search results. Ranking rules are applied in a default order which can be changed in the settings. You can add or remove rules and change their order of importance.
Ranking rules can also be updated directly through the global settings route along with the other settings.
Learn more about ranking rules and their relevancy.
NOTE
Updating the settings means overwriting the default settings of MeiliSearch. You can reset to default values using the DELETE
routes.
Get ranking rules
GET
/indexes/:index_uid/settings/ranking-rules
Get the ranking rules of an index.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Default value
An array that contains built-in ranking rules sorted by order of importance.
Example
$ curl \
-X GET 'http://localhost:7700/indexes/movies/settings/ranking-rules'
client.index('movies').getRankingRules()
client.index('movies').get_ranking_rules()
$client->index('movies')->getRankingRules();
index.ranking_rules
client.Settings("movies").GetRankingRules()
let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();
Response: 200 Ok
List the settings.
[
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"desc(release_date)"
]
Update ranking rules
POST
/indexes/:index_uid/settings/ranking-rules
Update the ranking rules of an index.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Body
An array that contain ranking rules sorted by order of importance.
To add your own ranking rule, you have to communicate either asc
for ascending order or desc
for descending order followed by the field name in brackets.
To apply an ascending sorting (results sorted by increasing value of the attribute):
asc(attribute_name)
To apply a descending sorting (results sorted by decreasing value of the attribute):
desc(attribute_name)
More information about the body.
Example
$ curl \
-X POST 'http://localhost:7700/indexes/movies/settings/ranking-rules' \
--data '[
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)"
]'
client.index('movies').updateRankingRules([
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
])
client.index('movies').update_ranking_rules([
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
])
$client->index('movies')->updateRankingRules([
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
]);
index.update_ranking_rules([
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
])
rankingRules := []string{
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)",
}
client.Settings("movies").UpdateRankingRules(rankingRules)
let ranking_rules = &[
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)",
];
let progress: Progress = movies.set_ranking_rules(ranking_rules).await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.
Reset ranking rules
DELETE
/indexes/:index_uid/settings/ranking-rules
Reset the ranking rules of an index to its default value.
Default value
An array that contains built-in ranking rules sorted by order of importance.
["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"]
To remove all ranking rules, which is not recommended in any case, you would send an empty array to the add or replace ranking rules route.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
$ curl \
-X DELETE 'http://localhost:7700/indexes/movies/settings/ranking-rules'
client.index('movies').resetRankingRules()
client.index('movies').reset_ranking_rules()
$client->index('movies')->resetRankingRules();
index.reset_ranking_rules
client.Settings("movies").ResetRankingRules()
let progress: Progress = movies.reset_ranking_rules().await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.