From f71f8451467bc0c191fc6fc08abbc4df29696fd5 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Tue, 2 Dec 2025 19:04:33 +0100 Subject: [PATCH 1/3] clarify custom ranking rule usage --- learn/relevancy/custom_ranking_rules.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/learn/relevancy/custom_ranking_rules.mdx b/learn/relevancy/custom_ranking_rules.mdx index 396de45845..2e03ac1597 100644 --- a/learn/relevancy/custom_ranking_rules.mdx +++ b/learn/relevancy/custom_ranking_rules.mdx @@ -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. @@ -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 role 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. From 795b2f0092ef2f1e2797ec2feb8bad9212ab690d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 2 Dec 2025 18:05:08 +0000 Subject: [PATCH 2/3] Update code samples [skip ci] --- .../code_samples_add_or_update_documents_1.mdx | 6 ++++-- .../code_samples_typo_tolerance_guide_2.mdx | 1 - .../code_samples_typo_tolerance_guide_5.mdx | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/snippets/samples/code_samples_add_or_update_documents_1.mdx b/snippets/samples/code_samples_add_or_update_documents_1.mdx index 53a1dd5260..c2d99d8e19 100644 --- a/snippets/samples/code_samples_add_or_update_documents_1.mdx +++ b/snippets/samples/code_samples_add_or_update_documents_1.mdx @@ -82,7 +82,8 @@ await index.UpdateDocumentsAsync(movie); #[derive(Serialize, Deserialize)] struct IncompleteMovie { id: usize, - title: String + title: String, + genres: String } let task: TaskInfo = client @@ -90,7 +91,8 @@ let task: TaskInfo = client .add_or_update(&[ IncompleteMovie { id: 287947, - title: "Shazam ⚡️".to_string() + title: "Shazam ⚡️".to_string(), + genres: "comedy".to_string() } ], None) .await diff --git a/snippets/samples/code_samples_typo_tolerance_guide_2.mdx b/snippets/samples/code_samples_typo_tolerance_guide_2.mdx index 1150ed453b..29c49b90cd 100644 --- a/snippets/samples/code_samples_typo_tolerance_guide_2.mdx +++ b/snippets/samples/code_samples_typo_tolerance_guide_2.mdx @@ -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) diff --git a/snippets/samples/code_samples_typo_tolerance_guide_5.mdx b/snippets/samples/code_samples_typo_tolerance_guide_5.mdx index be212b7fd6..8e0cc3c556 100644 --- a/snippets/samples/code_samples_typo_tolerance_guide_5.mdx +++ b/snippets/samples/code_samples_typo_tolerance_guide_5.mdx @@ -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(); +``` \ No newline at end of file From 6b8feab5acb56ac614c6b5bcfeb0cc3f0062232d Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Thu, 4 Dec 2025 16:27:30 +0100 Subject: [PATCH 3/3] Update learn/relevancy/custom_ranking_rules.mdx Co-authored-by: Many the fish --- learn/relevancy/custom_ranking_rules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/learn/relevancy/custom_ranking_rules.mdx b/learn/relevancy/custom_ranking_rules.mdx index 2e03ac1597..29cab65b29 100644 --- a/learn/relevancy/custom_ranking_rules.mdx +++ b/learn/relevancy/custom_ranking_rules.mdx @@ -26,7 +26,7 @@ Custom ranking rules sort results in lexicographical order. For example, `Elena` 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 role at a high position may result in a degraded search experience, since users will see documents in alphanumerical order instead of sorted by relevance. +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