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

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/movies/settings/ranking-rules'
  1. client.index('movies').getRankingRules()
  1. client.index('movies').get_ranking_rules()
  1. $client->index('movies')->getRankingRules();
  1. client.index("movies").getRankingRules();
  1. client.index('movies').ranking_rules
  1. client.Index("movies").GetRankingRules()
  1. let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();
  1. client.index("movies").getRankingRules { (result: Result<[String], Swift.Error>) in
  2. switch result {
  3. case .success(let rankingRules):
  4. print(rankingRules)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('movies').get_ranking_rules();

Response: 200 Ok

List the settings.

  1. [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:desc"
  9. ]

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

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings/ranking-rules' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '[
  5. "words",
  6. "typo",
  7. "proximity",
  8. "attribute",
  9. "sort",
  10. "exactness",
  11. "release_date:asc",
  12. "rank:desc"
  13. ]'
  1. client.index('movies').updateRankingRules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'exactness',
  7. 'release_date:asc',
  8. 'rank:desc'
  9. ])
  1. client.index('movies').update_ranking_rules([
  2. 'typo',
  3. 'proximity',
  4. 'attribute',
  5. 'sort',
  6. 'exactness',
  7. 'release_date:asc',
  8. 'rank:desc'
  9. ])
  1. $client->index('movies')->updateRankingRules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'sort',
  7. 'exactness',
  8. 'release_date:asc',
  9. 'rank:desc'
  10. ]);
  1. Settings settings = new Settings();
  2. settings.setRankingRules(new String[]
  3. {
  4. "words",
  5. "typo",
  6. "proximity",
  7. "attribute",
  8. "sort",
  9. "exactness",
  10. "release_date:asc",
  11. "rank:desc"
  12. });
  13. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_ranking_rules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'sort',
  7. 'exactness',
  8. 'release_date:asc',
  9. 'rank:desc'
  10. ])
  1. rankingRules := []string{
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:asc",
  9. "rank:desc",
  10. }
  11. client.Index("movies").UpdateRankingRules(&rankingRules)
  1. let ranking_rules = [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "sort",
  6. "exactness",
  7. "release_date:asc",
  8. ];
  9. let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap();
  1. let rankingRules: [String] = [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:asc",
  9. "rank:desc"
  10. ]
  11. client.index("movies").updateRankingRules(rankingRules) { (result: Result<Update, Swift.Error>) in
  12. switch result {
  13. case .success(let update):
  14. print(update)
  15. case .failure(let error):
  16. print(error)
  17. }
  18. }
  1. await client.index('movies').update_ranking_rules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'sort',
  7. 'exactness',
  8. 'release_date:asc',
  9. 'rank:desc'
  10. ]);

Response: 202 Accepted

  1. { "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:

  1. [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness"
  8. ]

Path Variables

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies/settings/ranking-rules'
  1. client.index('movies').resetRankingRules()
  1. client.index('movies').reset_ranking_rules()
  1. $client->index('movies')->resetRankingRules();
  1. //Not yet implemented
  1. client.index('movies').reset_ranking_rules
  1. client.Index("movies").ResetRankingRules()
  1. let progress: Progress = movies.reset_ranking_rules().await.unwrap();
  1. client.index("movies").resetRankingRules { (result: Result<Update, Swift.Error>) in
  2. switch result {
  3. case .success(let update):
  4. print(update)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('movies').resetRankingRules();

Response:

This updateId allows you to .