Skip to content

Commit a14c82c

Browse files
authored
Merge pull request #723 from kumarUjjawal/feat/typo
Add disableOnNumbers to typo tolerance settings
2 parents eab5f70 + 60eaf5d commit a14c82c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.code-samples.meilisearch.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,6 @@ typo_tolerance_guide_2: |-
989989
disable_on_words: None,
990990
min_word_size_for_typos: None,
991991
};
992-
993992
let task: TaskInfo = client
994993
.index("movies")
995994
.set_typo_tolerance(&typo_tolerance)
@@ -1024,6 +1023,18 @@ typo_tolerance_guide_4: |-
10241023
min_word_size_for_typos: Some(min_word_size_for_typos),
10251024
};
10261025
1026+
let task: TaskInfo = client
1027+
.index("movies")
1028+
.set_typo_tolerance(&typo_tolerance)
1029+
.await
1030+
.unwrap();
1031+
typo_tolerance_guide_5: |-
1032+
// Deactivate typo tolerance on numbers and other high entropy words
1033+
let typo_tolerance = TypoToleranceSettings {
1034+
disable_on_numbers: Some(true),
1035+
..Default::default()
1036+
};
1037+
10271038
let task: TaskInfo = client
10281039
.index("movies")
10291040
.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)]
@@ -1809,6 +1812,7 @@ impl<Http: HttpClient> Index<Http> {
18091812
/// disable_on_attributes: Some(vec!["title".to_string()]),
18101813
/// disable_on_words: Some(vec![]),
18111814
/// min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
1815+
/// ..Default::default()
18121816
/// };
18131817
///
18141818
/// let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
@@ -3053,6 +3057,8 @@ mod tests {
30533057
one_typo: Some(5),
30543058
two_typos: Some(9),
30553059
}),
3060+
// The server may return `false` explicitly for this new setting
3061+
disable_on_numbers: Some(false),
30563062
};
30573063

30583064
let res = index.get_typo_tolerance().await.unwrap();
@@ -3070,6 +3076,7 @@ mod tests {
30703076
one_typo: Some(5),
30713077
two_typos: Some(9),
30723078
}),
3079+
disable_on_numbers: Some(false),
30733080
};
30743081

30753082
let typo_tolerance = TypoToleranceSettings {
@@ -3095,6 +3102,7 @@ mod tests {
30953102
one_typo: Some(5),
30963103
two_typos: Some(9),
30973104
}),
3105+
disable_on_numbers: Some(false),
30983106
};
30993107

31003108
let typo_tolerance = TypoToleranceSettings {
@@ -3113,6 +3121,28 @@ mod tests {
31133121
assert_eq!(expected, default);
31143122
}
31153123

3124+
#[meilisearch_test]
3125+
async fn test_set_disable_on_numbers(client: Client, index: Index) {
3126+
// Set disable_on_numbers to true
3127+
let typo_tolerance = TypoToleranceSettings {
3128+
disable_on_numbers: Some(true),
3129+
..Default::default()
3130+
};
3131+
3132+
let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
3133+
client.wait_for_task(task_info, None, None).await.unwrap();
3134+
3135+
// Fetch and assert it is set
3136+
let res = index.get_typo_tolerance().await.unwrap();
3137+
assert_eq!(res.disable_on_numbers, Some(true));
3138+
3139+
// Reset and ensure it goes back to default false
3140+
let reset_task = index.reset_typo_tolerance().await.unwrap();
3141+
client.wait_for_task(reset_task, None, None).await.unwrap();
3142+
let default = index.get_typo_tolerance().await.unwrap();
3143+
assert_eq!(default.disable_on_numbers, Some(false));
3144+
}
3145+
31163146
#[meilisearch_test]
31173147
async fn test_get_proximity_precision(index: Index) {
31183148
let expected = "byWord".to_string();

0 commit comments

Comments
 (0)