mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
Merge #1131
1131: fix attributes to retrieve bug r=Kerollmops a=MarinPostma fix bug when using empty `attributeToRetrieve` Co-authored-by: mpostma <postma.marin@protonmail.com>
This commit is contained in:
commit
dec0e2545d
@ -193,9 +193,7 @@ impl<'a> SearchBuilder<'a> {
|
|||||||
.index
|
.index
|
||||||
.document(reader, Some(&all_attributes), doc.id)
|
.document(reader, Some(&all_attributes), doc.id)
|
||||||
.map_err(|e| Error::retrieve_document(doc.id.0, e))?
|
.map_err(|e| Error::retrieve_document(doc.id.0, e))?
|
||||||
.ok_or(Error::internal(
|
.unwrap_or_default();
|
||||||
"Impossible to retrieve the document; Corrupted data",
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let mut formatted = document.iter()
|
let mut formatted = document.iter()
|
||||||
.filter(|(key, _)| all_formatted.contains(key.as_str()))
|
.filter(|(key, _)| all_formatted.contains(key.as_str()))
|
||||||
|
@ -130,12 +130,13 @@ impl SearchQuery {
|
|||||||
restricted_attributes = available_attributes.clone();
|
restricted_attributes = available_attributes.clone();
|
||||||
} else {
|
} else {
|
||||||
restricted_attributes = HashSet::new();
|
restricted_attributes = HashSet::new();
|
||||||
|
search_builder.attributes_to_retrieve(HashSet::new());
|
||||||
for attr in attributes_to_retrieve {
|
for attr in attributes_to_retrieve {
|
||||||
if available_attributes.contains(attr) {
|
if available_attributes.contains(attr) {
|
||||||
restricted_attributes.insert(attr);
|
restricted_attributes.insert(attr);
|
||||||
search_builder.add_retrievable_field(attr.to_string());
|
search_builder.add_retrievable_field(attr.to_string());
|
||||||
} else {
|
} else {
|
||||||
warn!("The attributes {:?} present in attributesToCrop parameter doesn't exist", attr);
|
warn!("The attributes {:?} present in attributesToRetrieve parameter doesn't exist", attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,6 +554,16 @@ async fn search_with_attributes_to_retrieve() {
|
|||||||
test_post_get_search!(server, query, |response, _status_code| {
|
test_post_get_search!(server, query, |response, _status_code| {
|
||||||
assert_json_eq!(expected.clone(), response["hits"].clone(), ordered: false);
|
assert_json_eq!(expected.clone(), response["hits"].clone(), ordered: false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let query = json!({
|
||||||
|
"q": "cherry",
|
||||||
|
"limit": 1,
|
||||||
|
"attributesToRetrieve": [],
|
||||||
|
});
|
||||||
|
|
||||||
|
test_post_get_search!(server, query, |response, _status_code| {
|
||||||
|
assert_json_eq!(json!([{}]), response["hits"].clone(), ordered: false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
Loading…
Reference in New Issue
Block a user