Ranking rules

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.

.

NOTE

Updating the settings means overwriting the default settings of MeiliSearch. You can reset to default values using the DELETE routes.

GET

Path Variables

Default value

An array that contains built-in ranking rules sorted by order of importance.

  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. index.ranking_rules
  1. client.Settings("movies").GetRankingRules()
  1. let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();

Response: 200 Ok

List the settings.

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

POST

Update the ranking rules 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 either asc for ascending order or desc for descending order followed by the field name in brackets.

  • To apply a descending sorting (results sorted by decreasing value of the attribute): desc(attribute_name)

.

Example

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings/ranking-rules' \
  3. --data '[
  4. "typo",
  5. "words",
  6. "attribute",
  7. "wordsPosition",
  8. "exactness",
  9. "asc(release_date)",
  10. "desc(rank)"
  11. ]'
  1. client.index('movies').updateRankingRules([
  2. 'words',
  3. 'proximity',
  4. 'attribute',
  5. 'wordsPosition',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ])
  1. client.index('movies').update_ranking_rules([
  2. 'typo',
  3. 'words',
  4. 'proximity',
  5. 'attribute',
  6. 'wordsPosition',
  7. 'exactness',
  8. 'asc(release_date)',
  9. 'desc(rank)'
  10. ])
  1. $client->index('movies')->updateRankingRules([
  2. 'typo',
  3. 'words',
  4. 'proximity',
  5. 'attribute',
  6. 'wordsPosition',
  7. 'exactness',
  8. 'asc(release_date)',
  9. 'desc(rank)'
  10. ]);
  1. index.update_ranking_rules([
  2. 'typo',
  3. 'words',
  4. 'attribute',
  5. 'wordsPosition',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ])
  1. "typo",
  2. "words",
  3. "proximity",
  4. "attribute",
  5. "wordsPosition",
  6. "exactness",
  7. "asc(release_date)",
  8. "desc(rank)",
  9. }
  10. client.Settings("movies").UpdateRankingRules(rankingRules)
  1. let ranking_rules = [
  2. "typo",
  3. "words",
  4. "proximity",
  5. "attribute",
  6. "wordsPosition",
  7. "exactness",
  8. "asc(release_date)",
  9. "desc(rank)",
  10. ];
  11. let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

DELETE

Reset the of an index to its default value.

Default value

An array that contains sorted by order of importance.

  1. ["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"]

Path Variables

Example

  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. index.reset_ranking_rules
    1. let progress: Progress = movies.reset_ranking_rules().await.unwrap();

    Response: 202 Accepted

    This updateId allows you to .