diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 2203c0084..c99e6702e 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -381,9 +381,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -441,9 +441,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -500,9 +500,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name"], - "attributes_displayed": ["name"] + "attributeIdentifier": "id", + "attributesSearchable": ["name"], + "attributesDisplayed": ["name"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -552,9 +552,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -590,9 +590,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description", "age", "sex"], - "attributes_displayed": ["name", "description", "age", "sex"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description", "age", "sex"], + "attributesDisplayed": ["name", "description", "age", "sex"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -657,9 +657,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description", "city", "age", "sex"], - "attributes_displayed": ["name", "description", "city", "age", "sex"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description", "city", "age", "sex"], + "attributesDisplayed": ["name", "description", "city", "age", "sex"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -696,9 +696,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -773,9 +773,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description", "id"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description", "id"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -909,9 +909,9 @@ mod tests { let settings = { let data = r#" { - "attribute_identifier": "id", - "attributes_searchable": ["name", "description"], - "attributes_displayed": ["name", "description"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "description"], + "attributesDisplayed": ["name", "description"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); @@ -973,7 +973,7 @@ mod tests { let settings = { let data = r#" { - "ranking_rules": [ + "rankingRules": [ "_typo", "_words", "_proximity", @@ -982,9 +982,9 @@ mod tests { "_exact", "dsc(release_date)" ], - "attribute_identifier": "id", - "attributes_searchable": ["name", "release_date"], - "attributes_displayed": ["name", "release_date"] + "attributeIdentifier": "id", + "attributesSearchable": ["name", "release_date"], + "attributesDisplayed": ["name", "release_date"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); diff --git a/meilisearch-core/src/query_builder.rs b/meilisearch-core/src/query_builder.rs index 6acde187d..014198fb1 100644 --- a/meilisearch-core/src/query_builder.rs +++ b/meilisearch-core/src/query_builder.rs @@ -275,7 +275,7 @@ mod tests { let mut final_indexes = Vec::new(); for index in indexes { let name = index.attribute.to_string(); - schema.get_or_create(&name).unwrap(); + schema.get_or_create_empty(&name).unwrap(); let indexed_pos = schema.set_indexed(&name).unwrap().1; let index = DocIndex { attribute: indexed_pos.0, diff --git a/meilisearch-core/src/serde/serializer.rs b/meilisearch-core/src/serde/serializer.rs index e909b38b4..40525b8e6 100644 --- a/meilisearch-core/src/serde/serializer.rs +++ b/meilisearch-core/src/serde/serializer.rs @@ -305,7 +305,7 @@ pub fn serialize_value<'a, T: ?Sized>( where T: ser::Serialize, { - let field_id = schema.get_or_create(attribute)?; + let field_id = schema.get_or_create_empty(attribute.clone())?; serialize_value_with_id( txn, diff --git a/meilisearch-core/src/store/mod.rs b/meilisearch-core/src/store/mod.rs index d6d4e0ae2..cbc5ecb44 100644 --- a/meilisearch-core/src/store/mod.rs +++ b/meilisearch-core/src/store/mod.rs @@ -222,8 +222,6 @@ impl Index { let schema = self.main.schema(reader)?; let schema = schema.ok_or(Error::SchemaMissing)?; - // let attributes = attributes.map(|a| a.iter().filter_map(|name| schema.get_id(*name)).collect()); - let attributes = match attributes { Some(attributes) => Some(attributes.iter().filter_map(|name| schema.get_id(*name)).collect()), None => None, diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index a67d7eedf..095591cc1 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -47,11 +47,13 @@ pub fn apply_settings_update( let ranked_field: Vec = v.iter().filter_map(RankingRule::get_field).collect(); schema.update_ranked(ranked_field)?; index.main.put_ranking_rules(writer, v)?; + must_reindex = true; }, UpdateState::Clear => { let clear: Vec = Vec::new(); schema.update_ranked(clear)?; index.main.delete_ranking_rules(writer)?; + must_reindex = true; }, _ => (), } @@ -66,21 +68,27 @@ pub fn apply_settings_update( } match settings.attributes_searchable.clone() { - UpdateState::Update(v) => schema.update_indexed(v)?, + UpdateState::Update(v) => { + schema.update_indexed(v)?; + must_reindex = true; + }, UpdateState::Clear => { let clear: Vec = Vec::new(); schema.update_indexed(clear)?; + must_reindex = true; }, UpdateState::Nothing => (), UpdateState::Add(attrs) => { for attr in attrs { schema.set_indexed(attr)?; } + must_reindex = true; }, UpdateState::Delete(attrs) => { for attr in attrs { schema.remove_indexed(attr); } + must_reindex = true; } }; match settings.attributes_displayed.clone() { @@ -105,11 +113,10 @@ pub fn apply_settings_update( UpdateState::Update(v) => { schema.set_identifier(v)?; index.main.put_schema(writer, &schema)?; - }, - UpdateState::Clear => { - index.main.delete_schema(writer)?; + must_reindex = true; }, _ => { + println!("schema: {:?}", schema); index.main.put_schema(writer, &schema)?; }, }; @@ -150,6 +157,9 @@ pub fn apply_settings_update( docs_words_store, )?; } + if let UpdateState::Clear = settings.attribute_identifier { + index.main.delete_schema(writer)?; + } Ok(()) } diff --git a/meilisearch-http/src/data.rs b/meilisearch-http/src/data.rs index 47c50ec72..307f1aa65 100644 --- a/meilisearch-http/src/data.rs +++ b/meilisearch-http/src/data.rs @@ -84,7 +84,9 @@ impl DataInner { let mut fields_frequency = HashMap::<_, usize>::new(); for result in all_documents_fields { let (_, attr, _) = result?; - *fields_frequency.entry(schema.indexed_pos_to_field_id(attr).unwrap()).or_default() += 1; + if let Some(field_id) = schema.indexed_pos_to_field_id(attr) { + *fields_frequency.entry(field_id).or_default() += 1; + } } // convert attributes to their names