From 67dea08a0af4befe2b1fbe25643a4d2372da2634 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Wed, 6 Apr 2022 19:25:12 +0200 Subject: [PATCH] feat(http, lib): enable disable typos on attributes --- meilisearch-lib/src/index/index.rs | 7 +++++++ meilisearch-lib/src/index/updates.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/meilisearch-lib/src/index/index.rs b/meilisearch-lib/src/index/index.rs index 778205dbb..81dedbeba 100644 --- a/meilisearch-lib/src/index/index.rs +++ b/meilisearch-lib/src/index/index.rs @@ -182,10 +182,17 @@ impl Index { .into_iter() .collect(); + let disabled_attributes = self + .exact_attributes(txn)? + .into_iter() + .map(String::from) + .collect(); + let typo_tolerance = TypoSettings { enabled: Setting::Set(self.authorize_typos(txn)?), min_word_length_for_typo: Setting::Set(min_typo_word_len), disable_on_words: Setting::Set(disabled_words), + disable_on_attributes: Setting::Set(disabled_attributes), }; Ok(Settings { diff --git a/meilisearch-lib/src/index/updates.rs b/meilisearch-lib/src/index/updates.rs index f9bc990de..2a9638a6d 100644 --- a/meilisearch-lib/src/index/updates.rs +++ b/meilisearch-lib/src/index/updates.rs @@ -64,6 +64,9 @@ pub struct TypoSettings { #[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))] #[serde(default, skip_serializing_if = "Setting::is_not_set")] pub disable_on_words: Setting>, + #[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))] + #[serde(default, skip_serializing_if = "Setting::is_not_set")] + pub disable_on_attributes: Setting>, } /// Holds all the settings for an index. `T` can either be `Checked` if they represents settings /// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a @@ -377,6 +380,7 @@ pub fn apply_settings_to_builder( Setting::Reset => builder.reset_authorize_typos(), Setting::NotSet => (), } + match value.min_word_length_for_typo { Setting::Set(ref setting) => { match setting.one_typo { @@ -396,6 +400,7 @@ pub fn apply_settings_to_builder( } Setting::NotSet => (), } + match value.disable_on_words { Setting::Set(ref words) => { builder.set_exact_words(words.clone()); @@ -403,12 +408,22 @@ pub fn apply_settings_to_builder( Setting::Reset => builder.reset_exact_words(), Setting::NotSet => (), } + + match value.disable_on_attributes { + Setting::Set(ref words) => { + builder.set_exact_attributes(words.iter().cloned().collect()) + } + Setting::Reset => builder.reset_exact_attributes(), + Setting::NotSet => (), + } } Setting::Reset => { // all typo settings need to be reset here. builder.reset_authorize_typos(); builder.reset_min_word_len_one_typo(); builder.reset_min_word_len_two_typos(); + builder.reset_exact_words(); + builder.reset_exact_attributes(); } Setting::NotSet => (), }