mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
requested changes
This commit is contained in:
parent
4b5437a882
commit
d114250ebb
@ -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 => (),
|
||||
|
@ -520,7 +520,7 @@ fn get_indexed_attributes(schema: &Schema) -> Vec<String> {
|
||||
schema.indexed_name()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,6 +531,6 @@ fn get_displayed_attributes(schema: &Schema) -> HashSet<String> {
|
||||
schema.displayed_name()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<HashSet<String>>()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
@ -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], "*");
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user