diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 71e473ca2..14aad20c0 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] == "*" { + if v.len() == 1 && v[0] == "*" || v.is_empty() { schema.set_all_fields_as_indexed(); } else { schema.update_indexed(v)?; @@ -86,7 +86,7 @@ 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() == "*" { + if v.len() == 1 && v.iter().next().unwrap() == "*" || v.is_empty() { schema.set_all_fields_as_displayed(); } else { schema.update_displayed(v)? diff --git a/meilisearch-http/tests/settings.rs b/meilisearch-http/tests/settings.rs index 5b24156ea..db42417cf 100644 --- a/meilisearch-http/tests/settings.rs +++ b/meilisearch-http/tests/settings.rs @@ -426,10 +426,26 @@ async fn displayed_and_searchable_attributes_reset_to_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()[0], "color"); assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "color"); + server.delete_searchable_attributes().await; server.delete_displayed_attributes().await; + + let (response, _) = server.get_all_settings().await; + + assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*"); + assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*"); + + 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()[0], "color"); + assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "color"); + + server.update_all_settings(json!({ "searchableAttributes": [], "displayedAttributes": [] })).await; + let (response, _) = server.get_all_settings().await; assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*"); assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*");