From 42b3f52ef95416ca9f13ac46e70b77d24ba1deb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 28 May 2024 11:46:53 +0200 Subject: [PATCH] Introduce the SettingDiff only_additional_fields method --- milli/src/update/settings.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 24b32b6fa..c3e4ab3fa 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -1112,6 +1112,26 @@ impl InnerIndexSettingsDiff { || self.old.proximity_precision != self.new.proximity_precision } + /// Returns only the additional searchable fields if any + /// other searchable field has been modified, returns None. + pub fn only_additional_fields(&self) -> Option> { + match (&self.old.user_defined_searchable_fields, &self.new.user_defined_searchable_fields) { + (None, None) | (Some(_), None) => None, + (None, Some(new)) => Some(new.iter().cloned().collect()), + (Some(old), Some(new)) => { + let old: HashSet<_> = old.iter().cloned().collect(); + let new: HashSet<_> = new.iter().cloned().collect(); + if old.difference(&new).next().is_none() { + // if no field has been removed + // return only the additional ones + Some(&new - &old) + } else { + None + } + } + } + } + pub fn reindex_facets(&self) -> bool { let existing_fields = &self.new.existing_fields; if existing_fields.iter().any(|field| field.contains('.')) {