Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions learn/relevancy/custom_ranking_rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ description: Custom ranking rules promote certain documents over other search re

There are two types of ranking rules in Meilisearch: [built-in ranking rules](/learn/relevancy/ranking_rules) and custom ranking rules. This article describes the main aspects of using and configuring custom ranking rules.

Custom ranking rules promote certain documents over other search results that are otherwise equally relevant.

## Ascending and descending sorting rules

Meilisearch supports two types of custom rules: one for ascending sort and one for descending sort.
Expand All @@ -22,6 +20,14 @@ To add a custom ranking rule, you have to communicate the attribute name followe

You can add this rule to the existing list of ranking rules using the [update settings endpoint](/reference/api/settings#update-settings) or [update ranking rules endpoint](/reference/api/settings#update-ranking-rules).

## How to use custom ranking rules

Custom ranking rules sort results in lexicographical order. For example, `Elena` will rank higher than `Ryu` and lower than `11` in a descending sort.

Since this operation does not take into consideration document relevancy, in the majority of cases you should place custom ranking rules after the built-in ranking rules. This ensures that results are first sorted by relevancy, and the lexicographical sorting takes place only when two or more documents share the same ranking score.

Setting a custom ranking rule at a high position may result in a degraded search experience, since users will see documents in alphanumerical order instead of sorted by relevance.

## Example

Suppose you have a movie dataset. The documents contain the fields `release_date` with a timestamp as value, and `movie_ranking`, an integer that represents its ranking.
Expand Down
6 changes: 4 additions & 2 deletions snippets/samples/code_samples_add_or_update_documents_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ await index.UpdateDocumentsAsync(movie);
#[derive(Serialize, Deserialize)]
struct IncompleteMovie {
id: usize,
title: String
title: String,
genres: String
}

let task: TaskInfo = client
.index("movies")
.add_or_update(&[
IncompleteMovie {
id: 287947,
title: "Shazam ⚡️".to_string()
title: "Shazam ⚡️".to_string(),
genres: "comedy".to_string()
}
], None)
.await
Expand Down
1 change: 0 additions & 1 deletion snippets/samples/code_samples_typo_tolerance_guide_2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ let typo_tolerance = TypoToleranceSettings {
disable_on_words: None,
min_word_size_for_typos: None,
};

let task: TaskInfo = client
.index("movies")
.set_typo_tolerance(&typo_tolerance)
Expand Down
14 changes: 14 additions & 0 deletions snippets/samples/code_samples_typo_tolerance_guide_5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ client.Index("movies").UpdateTypoTolerance(&meilisearch.TypoTolerance{
DisableOnNumbers: true
})
```

```rust Rust
// Deactivate typo tolerance on numbers and other high entropy words
let typo_tolerance = TypoToleranceSettings {
disable_on_numbers: Some(true),
..Default::default()
};

let task: TaskInfo = client
.index("movies")
.set_typo_tolerance(&typo_tolerance)
.await
.unwrap();
```
</CodeGroup>