diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index d93c81acb..94563a5a9 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -350,7 +350,7 @@ impl Database { index.main.put_name(&mut writer, name)?; index.main.put_created_at(&mut writer)?; index.main.put_updated_at(&mut writer)?; - index.main.put_schema(&mut writer, &Schema::new())?; + index.main.put_schema(&mut writer, &Schema::default())?; let env_clone = self.env.clone(); let update_env_clone = self.update_env.clone(); diff --git a/meilisearch-core/src/facets.rs b/meilisearch-core/src/facets.rs index 11135c179..c4689ee87 100644 --- a/meilisearch-core/src/facets.rs +++ b/meilisearch-core/src/facets.rs @@ -245,8 +245,8 @@ mod test { #[test] fn test_facet_key() { - let mut schema = Schema::new(); - let id = schema.insert_and_index("hello").unwrap(); + let mut schema = Schema::default(); + let id = schema.insert_with_position("hello").unwrap().0; let facet_list = [schema.id("hello").unwrap()]; assert_eq!( FacetKey::from_str("hello:12", &schema, &facet_list).unwrap(), @@ -286,8 +286,8 @@ mod test { #[test] fn test_parse_facet_array() { use either::Either::{Left, Right}; - let mut schema = Schema::new(); - let _id = schema.insert_and_index("hello").unwrap(); + let mut schema = Schema::default(); + let _id = schema.insert_with_position("hello").unwrap(); let facet_list = [schema.id("hello").unwrap()]; assert_eq!( FacetFilter::from_str("[[\"hello:12\"]]", &schema, &facet_list).unwrap(), diff --git a/meilisearch-core/src/query_builder.rs b/meilisearch-core/src/query_builder.rs index 6f4485342..21a15cc9c 100644 --- a/meilisearch-core/src/query_builder.rs +++ b/meilisearch-core/src/query_builder.rs @@ -415,8 +415,7 @@ mod tests { let mut final_indexes = Vec::new(); for index in indexes { let name = index.attribute.to_string(); - schema.insert(&name).unwrap(); - let indexed_pos = schema.set_indexed(&name).unwrap().1; + let indexed_pos = schema.insert_with_position(&name).unwrap().1; let index = DocIndex { attribute: indexed_pos.0, ..*index @@ -447,7 +446,7 @@ mod tests { .postings_lists .put_postings_list(&mut writer, &word, &postings_list) .unwrap(); - } + } for ((docid, attr, _), count) in fields_counts { let prev = index @@ -461,7 +460,7 @@ mod tests { .documents_fields_counts .put_document_field_count(&mut writer, docid, IndexedPos(attr), prev + count) .unwrap(); - } + } writer.commit().unwrap(); diff --git a/meilisearch-core/src/settings.rs b/meilisearch-core/src/settings.rs index 50ac9c92c..f26865dd7 100644 --- a/meilisearch-core/src/settings.rs +++ b/meilisearch-core/src/settings.rs @@ -13,7 +13,7 @@ static RANKING_RULE_REGEX: Lazy = Lazy::new(|| { regex::Regex::new(r"(asc|desc)\(([a-zA-Z0-9-_]*)\)").unwrap() }); -#[derive(Default, Clone, Serialize, Deserialize)] +#[derive(Default, Clone, Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct Settings { #[serde(default, deserialize_with = "deserialize_some")] diff --git a/meilisearch-core/src/update/documents_addition.rs b/meilisearch-core/src/update/documents_addition.rs index d46aeb7fe..ec6af8171 100644 --- a/meilisearch-core/src/update/documents_addition.rs +++ b/meilisearch-core/src/update/documents_addition.rs @@ -126,13 +126,13 @@ where A: AsRef<[u8]>, let serialized = serde_json::to_vec(value)?; documents_fields.put_document_field(writer, document_id, field_id, &serialized)?; - if let Some(indexed_pos) = schema.is_indexed(field_id) { - let number_of_words = index_value(indexer, document_id, *indexed_pos, value); + if let Some(indexed_pos) = schema.is_searchable(field_id) { + let number_of_words = index_value(indexer, document_id, indexed_pos, value); if let Some(number_of_words) = number_of_words { documents_fields_counts.put_document_field_count( writer, document_id, - *indexed_pos, + indexed_pos, number_of_words as u16, )?; } @@ -228,7 +228,7 @@ pub fn apply_addition<'a, 'b, 'c>( for (document_id, document) in &documents_additions { // For each key-value pair in the document. for (attribute, value) in document { - let field_id = schema.insert_and_index(&attribute)?; + let (field_id, _) = schema.insert_with_position(&attribute)?; index_document( writer, index.documents_fields, diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 94e337265..7b82c1c6e 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -71,14 +71,14 @@ pub fn apply_settings_update( match settings.searchable_attributes.clone() { UpdateState::Update(v) => { if v.iter().any(|e| e == "*") || v.is_empty() { - schema.set_all_fields_as_indexed(); + schema.set_all_searchable(); } else { - schema.update_indexed(v)?; + schema.update_searchable(v)?; } must_reindex = true; }, UpdateState::Clear => { - schema.set_all_fields_as_indexed(); + schema.set_all_searchable(); must_reindex = true; }, UpdateState::Nothing => (), @@ -86,13 +86,13 @@ pub fn apply_settings_update( match settings.displayed_attributes.clone() { UpdateState::Update(v) => { if v.contains("*") || v.is_empty() { - schema.set_all_fields_as_displayed(); + schema.set_all_displayed(); } else { schema.update_displayed(v)? } }, UpdateState::Clear => { - schema.set_all_fields_as_displayed(); + schema.set_all_displayed(); }, UpdateState::Nothing => (), } diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index 42d5ca550..78893c47a 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -178,7 +178,7 @@ impl<'a> SearchBuilder<'a> { all_attributes.extend(&all_formatted); }, None => { - all_attributes.extend(schema.displayed_name()); + all_attributes.extend(schema.displayed_names()); // If we specified at least one attribute to highlight or crop then // all available attributes will be returned in the _formatted field. if self.attributes_to_highlight.is_some() || self.attributes_to_crop.is_some() { @@ -445,7 +445,7 @@ fn calculate_matches( continue; } } - if !schema.displayed_name().contains(attribute) { + if !schema.displayed_names().contains(&attribute) { continue; } if let Some(pos) = matches_result.get_mut(attribute) { diff --git a/meilisearch-http/src/routes/search.rs b/meilisearch-http/src/routes/search.rs index 52bbc31f0..0f86cafc8 100644 --- a/meilisearch-http/src/routes/search.rs +++ b/meilisearch-http/src/routes/search.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, HashSet}; +use std::collections::{HashMap, HashSet, BTreeSet}; use actix_web::{get, post, web, HttpResponse}; use log::warn; @@ -120,8 +120,8 @@ impl SearchQuery { search_builder.limit(limit); } - let available_attributes = schema.displayed_name(); - let mut restricted_attributes: HashSet<&str>; + let available_attributes = schema.displayed_names(); + let mut restricted_attributes: BTreeSet<&str>; match &self.attributes_to_retrieve { Some(attributes_to_retrieve) => { let attributes_to_retrieve: HashSet<&str> = @@ -129,7 +129,7 @@ impl SearchQuery { if attributes_to_retrieve.contains("*") { restricted_attributes = available_attributes.clone(); } else { - restricted_attributes = HashSet::new(); + restricted_attributes = BTreeSet::new(); search_builder.attributes_to_retrieve(HashSet::new()); for attr in attributes_to_retrieve { if available_attributes.contains(attr) { diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 00562eed0..773459b8c 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -523,11 +523,11 @@ async fn delete_attributes_for_faceting( } fn get_indexed_attributes(schema: &Schema) -> Vec { - if schema.is_indexed_all() { + if schema.is_searchable_all() { ["*"].iter().map(|s| s.to_string()).collect() } else { schema - .indexed_name() + .searchable_names() .iter() .map(|s| s.to_string()) .collect() @@ -539,7 +539,7 @@ fn get_displayed_attributes(schema: &Schema) -> BTreeSet { ["*"].iter().map(|s| s.to_string()).collect() } else { schema - .displayed_name() + .displayed_names() .iter() .map(|s| s.to_string()) .collect()