From e9f66b876687c8f29464d2724f92c3ab04634a65 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Tue, 22 Mar 2022 18:17:33 +0100 Subject: [PATCH] feat(all): introduce disable typo on words --- meilisearch-lib/src/index/index.rs | 9 +++++++++ meilisearch-lib/src/index/updates.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/meilisearch-lib/src/index/index.rs b/meilisearch-lib/src/index/index.rs index e95c64485..778205dbb 100644 --- a/meilisearch-lib/src/index/index.rs +++ b/meilisearch-lib/src/index/index.rs @@ -5,6 +5,7 @@ use std::ops::Deref; use std::path::Path; use std::sync::Arc; +use fst::IntoStreamer; use milli::heed::{EnvOpenOptions, RoTxn}; use milli::update::{IndexerConfig, Setting}; use milli::{obkv_to_json, FieldDistribution, FieldId}; @@ -174,9 +175,17 @@ impl Index { two_typos: Setting::Set(self.min_word_len_two_typos(txn)?), }; + let disabled_words = self + .exact_words(txn)? + .into_stream() + .into_strs()? + .into_iter() + .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), }; Ok(Settings { diff --git a/meilisearch-lib/src/index/updates.rs b/meilisearch-lib/src/index/updates.rs index 2c4b7c1c5..f9bc990de 100644 --- a/meilisearch-lib/src/index/updates.rs +++ b/meilisearch-lib/src/index/updates.rs @@ -61,6 +61,9 @@ pub struct TypoSettings { #[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))] #[serde(default, skip_serializing_if = "Setting::is_not_set")] pub min_word_length_for_typo: Setting, + #[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))] + #[serde(default, skip_serializing_if = "Setting::is_not_set")] + pub disable_on_words: 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 @@ -393,6 +396,13 @@ pub fn apply_settings_to_builder( } Setting::NotSet => (), } + match value.disable_on_words { + Setting::Set(ref words) => { + builder.set_exact_words(words.clone()); + } + Setting::Reset => builder.reset_exact_words(), + Setting::NotSet => (), + } } Setting::Reset => { // all typo settings need to be reset here.