mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 16:24:26 +01:00
Merge #2296
2296: disable typo for attributes r=curquiza a=MarinPostma Introduce the disable typos on attribute feature as per https://github.com/meilisearch/specifications/pull/117. Co-authored-by: ad hoc <postma.marin@protonmail.com>
This commit is contained in:
commit
d5e33637b7
@ -182,10 +182,17 @@ impl Index {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let disabled_attributes = self
|
||||||
|
.exact_attributes(txn)?
|
||||||
|
.into_iter()
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let typo_tolerance = TypoSettings {
|
let typo_tolerance = TypoSettings {
|
||||||
enabled: Setting::Set(self.authorize_typos(txn)?),
|
enabled: Setting::Set(self.authorize_typos(txn)?),
|
||||||
min_word_length_for_typo: Setting::Set(min_typo_word_len),
|
min_word_length_for_typo: Setting::Set(min_typo_word_len),
|
||||||
disable_on_words: Setting::Set(disabled_words),
|
disable_on_words: Setting::Set(disabled_words),
|
||||||
|
disable_on_attributes: Setting::Set(disabled_attributes),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Settings {
|
Ok(Settings {
|
||||||
|
@ -64,6 +64,9 @@ pub struct TypoSettings {
|
|||||||
#[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))]
|
#[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))]
|
||||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||||
pub disable_on_words: Setting<BTreeSet<String>>,
|
pub disable_on_words: Setting<BTreeSet<String>>,
|
||||||
|
#[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))]
|
||||||
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||||
|
pub disable_on_attributes: Setting<BTreeSet<String>>,
|
||||||
}
|
}
|
||||||
/// Holds all the settings for an index. `T` can either be `Checked` if they represents settings
|
/// 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
|
/// 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::Reset => builder.reset_authorize_typos(),
|
||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match value.min_word_length_for_typo {
|
match value.min_word_length_for_typo {
|
||||||
Setting::Set(ref setting) => {
|
Setting::Set(ref setting) => {
|
||||||
match setting.one_typo {
|
match setting.one_typo {
|
||||||
@ -396,6 +400,7 @@ pub fn apply_settings_to_builder(
|
|||||||
}
|
}
|
||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match value.disable_on_words {
|
match value.disable_on_words {
|
||||||
Setting::Set(ref words) => {
|
Setting::Set(ref words) => {
|
||||||
builder.set_exact_words(words.clone());
|
builder.set_exact_words(words.clone());
|
||||||
@ -403,12 +408,22 @@ pub fn apply_settings_to_builder(
|
|||||||
Setting::Reset => builder.reset_exact_words(),
|
Setting::Reset => builder.reset_exact_words(),
|
||||||
Setting::NotSet => (),
|
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 => {
|
Setting::Reset => {
|
||||||
// all typo settings need to be reset here.
|
// all typo settings need to be reset here.
|
||||||
builder.reset_authorize_typos();
|
builder.reset_authorize_typos();
|
||||||
builder.reset_min_word_len_one_typo();
|
builder.reset_min_word_len_one_typo();
|
||||||
builder.reset_min_word_len_two_typos();
|
builder.reset_min_word_len_two_typos();
|
||||||
|
builder.reset_exact_words();
|
||||||
|
builder.reset_exact_attributes();
|
||||||
}
|
}
|
||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user