diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index aa7d3f505..33d1cc11b 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -84,8 +84,7 @@ pub fn apply_settings_update( must_reindex = true; }, UpdateState::Clear => { - let clear: Vec<&str> = Vec::new(); - schema.update_indexed(clear)?; + schema.set_all_fields_indexed(); must_reindex = true; }, UpdateState::Nothing => (), @@ -93,8 +92,7 @@ pub fn apply_settings_update( match settings.displayed_attributes.clone() { UpdateState::Update(v) => schema.update_displayed(v)?, UpdateState::Clear => { - let clear: Vec<&str> = Vec::new(); - schema.update_displayed(clear)?; + schema.set_all_fields_displayed(); }, UpdateState::Nothing => (), } diff --git a/meilisearch-schema/src/fields_map.rs b/meilisearch-schema/src/fields_map.rs index 6243a554b..6505b33fb 100644 --- a/meilisearch-schema/src/fields_map.rs +++ b/meilisearch-schema/src/fields_map.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::collections::hash_map::Iter; use serde::{Deserialize, Serialize}; @@ -45,8 +46,13 @@ impl FieldsMap { pub fn name>(&self, id: I) -> Option<&str> { self.id_map.get(&id.into()).map(|s| s.as_str()) } + + pub fn iter(&self) -> Iter<'_, String, FieldId> { + self.name_map.iter() + } } + #[cfg(test)] mod tests { use super::*; diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index d66693bc9..da6d615b1 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -190,6 +190,25 @@ impl Schema { Ok(()) } + pub fn set_all_fields_indexed(&mut self) { + self.indexed.clear(); + self.indexed_map.clear(); + + for (_name, id) in self.fields_map.iter() { + let pos = self.indexed.len() as u16; + self.indexed.push(*id); + self.indexed_map.insert(*id, pos.into()); + } + } + + pub fn set_all_fields_displayed(&mut self) { + self.displayed.clear(); + + for (_name, id) in self.fields_map.iter() { + self.displayed.insert(*id); + } + } + pub fn accept_new_fields(&self) -> bool { self.accept_new_fields }