Skip to content

Commit 1015fd8

Browse files
Clarify custom ranking rule usage (#3419)
--------- Co-authored-by: Many the fish <[email protected]>
1 parent 5b9ff60 commit 1015fd8

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

learn/relevancy/custom_ranking_rules.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ description: Custom ranking rules promote certain documents over other search re
66

77
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.
88

9-
Custom ranking rules promote certain documents over other search results that are otherwise equally relevant.
10-
119
## Ascending and descending sorting rules
1210

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

2321
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).
2422

23+
## How to use custom ranking rules
24+
25+
Custom ranking rules sort results in lexicographical order. For example, `Elena` will rank higher than `Ryu` and lower than `11` in a descending sort.
26+
27+
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.
28+
29+
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.
30+
2531
## Example
2632

2733
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.

snippets/samples/code_samples_add_or_update_documents_1.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ await index.UpdateDocumentsAsync(movie);
8282
#[derive(Serialize, Deserialize)]
8383
struct IncompleteMovie {
8484
id: usize,
85-
title: String
85+
title: String,
86+
genres: String
8687
}
8788

8889
let task: TaskInfo = client
8990
.index("movies")
9091
.add_or_update(&[
9192
IncompleteMovie {
9293
id: 287947,
93-
title: "Shazam ⚡️".to_string()
94+
title: "Shazam ⚡️".to_string(),
95+
genres: "comedy".to_string()
9496
}
9597
], None)
9698
.await

snippets/samples/code_samples_typo_tolerance_guide_2.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ let typo_tolerance = TypoToleranceSettings {
5959
disable_on_words: None,
6060
min_word_size_for_typos: None,
6161
};
62-
6362
let task: TaskInfo = client
6463
.index("movies")
6564
.set_typo_tolerance(&typo_tolerance)

snippets/samples/code_samples_typo_tolerance_guide_5.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,18 @@ client.Index("movies").UpdateTypoTolerance(&meilisearch.TypoTolerance{
4242
DisableOnNumbers: true
4343
})
4444
```
45+
46+
```rust Rust
47+
// Deactivate typo tolerance on numbers and other high entropy words
48+
let typo_tolerance = TypoToleranceSettings {
49+
disable_on_numbers: Some(true),
50+
..Default::default()
51+
};
52+
53+
let task: TaskInfo = client
54+
.index("movies")
55+
.set_typo_tolerance(&typo_tolerance)
56+
.await
57+
.unwrap();
58+
```
4559
</CodeGroup>

0 commit comments

Comments
 (0)