diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 14aad20c0..94e337265 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -70,7 +70,7 @@ pub fn apply_settings_update( match settings.searchable_attributes.clone() { UpdateState::Update(v) => { - if v.len() == 1 && v[0] == "*" || v.is_empty() { + if v.iter().any(|e| e == "*") || v.is_empty() { schema.set_all_fields_as_indexed(); } else { schema.update_indexed(v)?; @@ -85,15 +85,13 @@ pub fn apply_settings_update( } match settings.displayed_attributes.clone() { UpdateState::Update(v) => { - // safe to unwrap because len is 1 - if v.len() == 1 && v.iter().next().unwrap() == "*" || v.is_empty() { + if v.contains("*") || v.is_empty() { schema.set_all_fields_as_displayed(); } else { schema.update_displayed(v)? } }, UpdateState::Clear => { - println!("\n\n\n\nHERRE\n\n\n"); schema.set_all_fields_as_displayed(); }, UpdateState::Nothing => (), diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 65e884800..8de584c67 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -520,7 +520,7 @@ fn get_indexed_attributes(schema: &Schema) -> Vec { schema.indexed_name() .iter() .map(|s| s.to_string()) - .collect::>() + .collect() } } @@ -531,6 +531,6 @@ fn get_displayed_attributes(schema: &Schema) -> HashSet { schema.displayed_name() .iter() .map(|s| s.to_string()) - .collect::>() + .collect() } } diff --git a/meilisearch-http/tests/settings.rs b/meilisearch-http/tests/settings.rs index db42417cf..92114faa3 100644 --- a/meilisearch-http/tests/settings.rs +++ b/meilisearch-http/tests/settings.rs @@ -435,6 +435,8 @@ async fn displayed_and_searchable_attributes_reset_to_wildcard() { let (response, _) = server.get_all_settings().await; + assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1); + assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1); assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*"); assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*"); @@ -447,6 +449,22 @@ async fn displayed_and_searchable_attributes_reset_to_wildcard() { server.update_all_settings(json!({ "searchableAttributes": [], "displayedAttributes": [] })).await; let (response, _) = server.get_all_settings().await; + + assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1); + assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1); + assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*"); + assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*"); +} + +#[actix_rt::test] +async fn settings_that_contains_wildcard_is_wildcard() { + let mut server = common::Server::test_server().await; + server.update_all_settings(json!({ "searchableAttributes": ["color", "*"], "displayedAttributes": ["color", "*"] })).await; + + let (response, _) = server.get_all_settings().await; + + assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1); + assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1); assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*"); assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*"); } diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index 12db42a3a..cbeccdffa 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -276,9 +276,7 @@ impl Schema { pub fn is_displayed(&self, id: FieldId) -> bool { match self.displayed { - OptionAll::Some(ref v) => { - v.get(&id).is_some() - } + OptionAll::Some(ref v) => v.contains(&id), OptionAll::All => true, OptionAll::None => false, }