Skip to content
Open
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
13 changes: 13 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,19 @@ typo_tolerance_guide_2: |-
min_word_size_for_typos: None,
};

typo_tolerance_guide_5: |-
// 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();

let task: TaskInfo = client
.index("movies")
.set_typo_tolerance(&typo_tolerance)
Expand Down
30 changes: 30 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct TypoToleranceSettings {
pub disable_on_attributes: Option<Vec<String>>,
pub disable_on_words: Option<Vec<String>>,
pub min_word_size_for_typos: Option<MinWordSizeForTypos>,
/// Deactivate typo tolerance on high entropy words such as numbers
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_on_numbers: Option<bool>,
}

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

let res = index.get_typo_tolerance().await.unwrap();
Expand All @@ -3055,6 +3061,7 @@ mod tests {
one_typo: Some(5),
two_typos: Some(9),
}),
disable_on_numbers: Some(false),
};

let typo_tolerance = TypoToleranceSettings {
Expand All @@ -3080,6 +3087,7 @@ mod tests {
one_typo: Some(5),
two_typos: Some(9),
}),
disable_on_numbers: Some(false),
};

let typo_tolerance = TypoToleranceSettings {
Expand All @@ -3098,6 +3106,28 @@ mod tests {
assert_eq!(expected, default);
}

#[meilisearch_test]
async fn test_set_disable_on_numbers(client: Client, index: Index) {
// Set disable_on_numbers to true
let typo_tolerance = TypoToleranceSettings {
disable_on_numbers: Some(true),
..Default::default()
};

let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
client.wait_for_task(task_info, None, None).await.unwrap();

// Fetch and assert it is set
let res = index.get_typo_tolerance().await.unwrap();
assert_eq!(res.disable_on_numbers, Some(true));

// Reset and ensure it goes back to default false
let reset_task = index.reset_typo_tolerance().await.unwrap();
client.wait_for_task(reset_task, None, None).await.unwrap();
let default = index.get_typo_tolerance().await.unwrap();
assert_eq!(default.disable_on_numbers, Some(false));
}

#[meilisearch_test]
async fn test_get_proximity_precision(index: Index) {
let expected = "byWord".to_string();
Expand Down