Skip to content

Commit 30c5b31

Browse files
committed
Add disableOnNumbers to typo tolerance settings
1 parent e90a3c2 commit 30c5b31

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,19 @@ typo_tolerance_guide_2: |-
958958
min_word_size_for_typos: None,
959959
};
960960
961+
typo_tolerance_guide_5: |-
962+
// Deactivate typo tolerance on numbers and other high entropy words
963+
let typo_tolerance = TypoToleranceSettings {
964+
disable_on_numbers: Some(true),
965+
..Default::default()
966+
};
967+
968+
let task: TaskInfo = client
969+
.index("movies")
970+
.set_typo_tolerance(&typo_tolerance)
971+
.await
972+
.unwrap();
973+
961974
let task: TaskInfo = client
962975
.index("movies")
963976
.set_typo_tolerance(&typo_tolerance)

src/settings.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub struct TypoToleranceSettings {
2828
pub disable_on_attributes: Option<Vec<String>>,
2929
pub disable_on_words: Option<Vec<String>>,
3030
pub min_word_size_for_typos: Option<MinWordSizeForTypos>,
31+
/// Deactivate typo tolerance on high entropy words such as numbers
32+
#[serde(skip_serializing_if = "Option::is_none")]
33+
pub disable_on_numbers: Option<bool>,
3134
}
3235

3336
#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Serialize)]
@@ -1795,6 +1798,7 @@ impl<Http: HttpClient> Index<Http> {
17951798
/// disable_on_attributes: Some(vec!["title".to_string()]),
17961799
/// disable_on_words: Some(vec![]),
17971800
/// min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
1801+
/// ..Default::default()
17981802
/// };
17991803
///
18001804
/// let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
@@ -3038,6 +3042,8 @@ mod tests {
30383042
one_typo: Some(5),
30393043
two_typos: Some(9),
30403044
}),
3045+
// The server may return `false` explicitly for this new setting
3046+
disable_on_numbers: Some(false),
30413047
};
30423048

30433049
let res = index.get_typo_tolerance().await.unwrap();
@@ -3055,6 +3061,7 @@ mod tests {
30553061
one_typo: Some(5),
30563062
two_typos: Some(9),
30573063
}),
3064+
disable_on_numbers: Some(false),
30583065
};
30593066

30603067
let typo_tolerance = TypoToleranceSettings {
@@ -3080,6 +3087,7 @@ mod tests {
30803087
one_typo: Some(5),
30813088
two_typos: Some(9),
30823089
}),
3090+
disable_on_numbers: Some(false),
30833091
};
30843092

30853093
let typo_tolerance = TypoToleranceSettings {
@@ -3098,6 +3106,28 @@ mod tests {
30983106
assert_eq!(expected, default);
30993107
}
31003108

3109+
#[meilisearch_test]
3110+
async fn test_set_disable_on_numbers(client: Client, index: Index) {
3111+
// Set disable_on_numbers to true
3112+
let typo_tolerance = TypoToleranceSettings {
3113+
disable_on_numbers: Some(true),
3114+
..Default::default()
3115+
};
3116+
3117+
let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
3118+
client.wait_for_task(task_info, None, None).await.unwrap();
3119+
3120+
// Fetch and assert it is set
3121+
let res = index.get_typo_tolerance().await.unwrap();
3122+
assert_eq!(res.disable_on_numbers, Some(true));
3123+
3124+
// Reset and ensure it goes back to default false
3125+
let reset_task = index.reset_typo_tolerance().await.unwrap();
3126+
client.wait_for_task(reset_task, None, None).await.unwrap();
3127+
let default = index.get_typo_tolerance().await.unwrap();
3128+
assert_eq!(default.disable_on_numbers, Some(false));
3129+
}
3130+
31013131
#[meilisearch_test]
31023132
async fn test_get_proximity_precision(index: Index) {
31033133
let expected = "byWord".to_string();

0 commit comments

Comments
 (0)