mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
implements the synonyms in transplant
This commit is contained in:
parent
b119bb4ab0
commit
18d4d6097a
8 changed files with 50 additions and 56 deletions
|
@ -84,6 +84,17 @@ impl Index {
|
|||
.unwrap_or_else(BTreeSet::new);
|
||||
let distinct_field = self.distinct_field(&txn)?.map(String::from);
|
||||
|
||||
let synonyms = self
|
||||
.synonyms(&txn)?
|
||||
.iter()
|
||||
.map(|(key, values)| {
|
||||
(
|
||||
key.join(" "),
|
||||
values.iter().map(|value| value.join(" ")).collect(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Settings {
|
||||
displayed_attributes: Some(displayed_attributes),
|
||||
searchable_attributes: Some(searchable_attributes),
|
||||
|
@ -91,6 +102,7 @@ impl Index {
|
|||
ranking_rules: Some(Some(criteria)),
|
||||
stop_words: Some(Some(stop_words)),
|
||||
distinct_attribute: Some(distinct_field),
|
||||
synonyms: Some(Some(synonyms)),
|
||||
_kind: PhantomData,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::collections::{BTreeSet, BTreeMap, HashSet};
|
||||
use std::io;
|
||||
use std::marker::PhantomData;
|
||||
use std::num::NonZeroUsize;
|
||||
|
@ -70,6 +70,12 @@ pub struct Settings<T> {
|
|||
deserialize_with = "deserialize_some",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_some",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub distinct_attribute: Option<Option<String>>,
|
||||
|
||||
#[serde(skip)]
|
||||
|
@ -84,6 +90,7 @@ impl Settings<Checked> {
|
|||
filterable_attributes: Some(None),
|
||||
ranking_rules: Some(None),
|
||||
stop_words: Some(None),
|
||||
synonyms: Some(None),
|
||||
distinct_attribute: Some(None),
|
||||
_kind: PhantomData,
|
||||
}
|
||||
|
@ -96,6 +103,7 @@ impl Settings<Checked> {
|
|||
filterable_attributes,
|
||||
ranking_rules,
|
||||
stop_words,
|
||||
synonyms,
|
||||
distinct_attribute,
|
||||
..
|
||||
} = self;
|
||||
|
@ -106,6 +114,7 @@ impl Settings<Checked> {
|
|||
filterable_attributes,
|
||||
ranking_rules,
|
||||
stop_words,
|
||||
synonyms,
|
||||
distinct_attribute,
|
||||
_kind: PhantomData,
|
||||
}
|
||||
|
@ -142,6 +151,7 @@ impl Settings<Unchecked> {
|
|||
filterable_attributes: self.filterable_attributes,
|
||||
ranking_rules: self.ranking_rules,
|
||||
stop_words: self.stop_words,
|
||||
synonyms: self.synonyms,
|
||||
distinct_attribute: self.distinct_attribute,
|
||||
_kind: PhantomData,
|
||||
}
|
||||
|
@ -271,6 +281,13 @@ impl Index {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(ref synonyms) = settings.synonyms {
|
||||
match synonyms {
|
||||
Some(synonyms) => builder.set_synonyms(synonyms.clone().into_iter().collect()),
|
||||
_ => builder.reset_synonyms(),
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref distinct_attribute) = settings.distinct_attribute {
|
||||
match distinct_attribute {
|
||||
Some(attr) => builder.set_distinct_field(attr.clone()),
|
||||
|
@ -332,6 +349,7 @@ mod test {
|
|||
filterable_attributes: None,
|
||||
ranking_rules: None,
|
||||
stop_words: None,
|
||||
synonyms: None,
|
||||
distinct_attribute: None,
|
||||
_kind: PhantomData::<Unchecked>,
|
||||
};
|
||||
|
@ -351,6 +369,7 @@ mod test {
|
|||
filterable_attributes: None,
|
||||
ranking_rules: None,
|
||||
stop_words: None,
|
||||
synonyms: None,
|
||||
distinct_attribute: None,
|
||||
_kind: PhantomData::<Unchecked>,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue