Ranking rules
Ranking rules are built-in rules that allow you to customize the relevancy of your search results. They are stored in an array and applied in order of appearance.
Ranking rules can also be updated directly through the global settings route along with the other settings.
To learn more about ranking rules, refer to our .
WARNING
Updating the settings means overwriting the default settings of MeiliSearch. You can reset to default values using the DELETE
routes.
GET
Get the ranking rules of an index.
Path variables
Default value
An array that contains in order of importance.
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
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();
client.index("movies").getRankingRules();
client.index('movies').ranking_rules
client.Index("movies").GetRankingRules()
let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();
client.index("movies").getRankingRules { (result: Result<[String], Swift.Error>) in
switch result {
case .success(let rankingRules):
print(rankingRules)
case .failure(let error):
print(error)
}
}
await client.index('movies').get_ranking_rules();
Response: 200 Ok
List the settings.
[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:desc"
]
POST
Update the of an index.
Path variables
Body
An array that contain ranking rules sorted by order of importance.
To add your own ranking rule, you have to communicate an attribute followed by a colon (:
) and either asc
for ascending order or desc
for descending order.
To apply an ascending sort (results sorted by increasing value):
attribute_name:asc
To apply a descending sort (results sorted by decreasing value):
attribute_name:desc
More information about the body.
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
curl \
-X POST 'http://localhost:7700/indexes/movies/settings/ranking-rules' \
-H 'Content-Type: application/json' \
--data-binary '[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc"
]'
client.index('movies').updateRankingRules([
'words',
'typo',
'proximity',
'attribute',
'exactness',
'release_date:asc',
'rank:desc'
])
client.index('movies').update_ranking_rules([
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:asc',
'rank:desc'
])
$client->index('movies')->updateRankingRules([
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:asc',
'rank:desc'
]);
Settings settings = new Settings();
settings.setRankingRules(new String[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc"
});
client.index("movies").updateSettings(settings);
client.index('movies').update_ranking_rules([
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:asc',
'rank:desc'
])
rankingRules := []string{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc",
}
client.Index("movies").UpdateRankingRules(&rankingRules)
let ranking_rules = [
"words",
"typo",
"proximity",
"sort",
"exactness",
"release_date:asc",
];
let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap();
let rankingRules: [String] = [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc"
]
client.index("movies").updateRankingRules(rankingRules) { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('movies').update_ranking_rules([
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:asc',
'rank:desc'
]);
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to .
DELETE
Reset the ranking rules of an index to their default value.
TIP
Note that resetting the ranking rules is not the same as removing them.
To remove a ranking rule, use the .
Default value
An array that contains the in the following order:
[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness"
]
Path Variables
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
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();
//Not yet implemented
client.index('movies').reset_ranking_rules
client.Index("movies").ResetRankingRules()
let progress: Progress = movies.reset_ranking_rules().await.unwrap();
client.index("movies").resetRankingRules { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('movies').resetRankingRules();
Response:
This updateId
allows you to .