diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 94e337265..b02ad4fe0 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::{BTreeMap, BTreeSet, btree_map::Entry}; use heed::Result as ZResult; use fst::{set::OpBuilder, SetBuilder}; @@ -126,7 +126,7 @@ pub fn apply_settings_update( } match settings.synonyms { - UpdateState::Update(synonyms) => apply_synonyms_update(writer, index, synonyms)?, + UpdateState::Update(synonyms) => apply_synonyms_update(writer, index, transform_synonyms(synonyms))? , UpdateState::Clear => apply_synonyms_update(writer, index, BTreeMap::new())?, UpdateState::Nothing => (), } @@ -138,6 +138,23 @@ pub fn apply_settings_update( Ok(()) } +fn transform_synonyms(synonyms: BTreeMap>) -> BTreeMap> { + synonyms + .into_iter() + .fold(BTreeMap::new(), |mut map, (key, values)| { + let deunicoded = deunicode::deunicode(&key); + match map.entry(deunicoded) { + Entry::Vacant(entry) => { + entry.insert(values); + } + Entry::Occupied(mut entry) => { + entry.get_mut().extend_from_slice(&values); + } + } + map + }) +} + fn apply_attributes_for_faceting_update( writer: &mut heed::RwTxn, index: &store::Index,