diff --git a/meilisearch-core/src/query_builder.rs b/meilisearch-core/src/query_builder.rs index 16b1645ae..6acde187d 100644 --- a/meilisearch-core/src/query_builder.rs +++ b/meilisearch-core/src/query_builder.rs @@ -145,6 +145,7 @@ mod tests { use crate::bucket_sort::SimpleMatch; use crate::database::Database; use crate::store::Index; + use meilisearch_schema::Schema; fn set_from_stream<'f, I, S>(stream: I) -> Set where @@ -268,18 +269,34 @@ mod tests { let mut postings_lists = HashMap::new(); let mut fields_counts = HashMap::<_, u16>::new(); + let mut schema = Schema::default(); + for (word, indexes) in iter { + let mut final_indexes = Vec::new(); + for index in indexes { + let name = index.attribute.to_string(); + schema.get_or_create(&name).unwrap(); + let indexed_pos = schema.set_indexed(&name).unwrap().1; + let index = DocIndex { + attribute: indexed_pos.0, + ..*index + }; + final_indexes.push(index); + } + let word = word.to_lowercase().into_bytes(); words_fst.insert(word.clone()); postings_lists .entry(word) .or_insert_with(Vec::new) - .extend_from_slice(indexes); - for idx in indexes { + .extend_from_slice(&final_indexes); + for idx in final_indexes { fields_counts.insert((idx.document_id, idx.attribute, idx.word_index), 1); } } + index.main.put_schema(&mut writer, &schema).unwrap(); + let words_fst = Set::from_iter(words_fst).unwrap(); index.main.put_words_fst(&mut writer, &words_fst).unwrap(); diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 13b8a1167..da9d23047 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -44,8 +44,6 @@ pub fn apply_settings_update( } }; - println!("settings: {:?}", settings); - match settings.ranking_rules { UpdateState::Update(v) => { index.main.put_ranking_rules(writer, v)?; @@ -126,8 +124,6 @@ pub fn apply_settings_update( index.main.put_schema(writer, &schema)?; - println!("schema: {:?}", schema); - match settings.stop_words { UpdateState::Update(stop_words) => { if apply_stop_words_update(writer, index, stop_words)? { diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index 8b7fd30e3..aa9a194d0 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -109,6 +109,9 @@ impl Schema { pub fn set_indexed>(&mut self, name: S) -> SResult<(FieldId, IndexedPos)> { let id = self.fields_map.insert(name.into())?; + if let Some(indexed_pos) = self.indexed_map.get(&id) { + return Ok((id, *indexed_pos)) + }; let pos = self.indexed.len() as u16; self.indexed.push(id); self.indexed_map.insert(id, pos.into());