diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index 7b2bb4628..ed5d88230 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -108,9 +108,18 @@ async fn get_all_documents( params: web::Query, ) -> Result { let attributes_to_retrieve = params - .attributes_to_retrieve - .as_ref() - .map(|attrs| attrs.split(',').map(String::from).collect::>()); + .attributes_to_retrieve + .as_ref() + .and_then(|attrs| { + let mut names = Vec::new(); + for name in attrs.split(',').map(String::from) { + if name == "*" { + return None + } + names.push(name); + } + Some(names) + }); match data .retrieve_documents( diff --git a/meilisearch-http/tests/documents/get_documents.rs b/meilisearch-http/tests/documents/get_documents.rs index 73e29576c..24809532e 100644 --- a/meilisearch-http/tests/documents/get_documents.rs +++ b/meilisearch-http/tests/documents/get_documents.rs @@ -182,6 +182,23 @@ async fn test_get_all_documents_attributes_to_retrieve() { 0 ); + let (response, code) = index + .get_all_documents(GetAllDocumentsOptions { + attributes_to_retrieve: Some(vec!["wrong"]), + ..Default::default() + }) + .await; + assert_eq!(code, 200); + assert_eq!(response.as_array().unwrap().len(), 20); + assert_eq!( + response.as_array().unwrap()[0] + .as_object() + .unwrap() + .keys() + .count(), + 0 + ); + let (response, code) = index .get_all_documents(GetAllDocumentsOptions { attributes_to_retrieve: Some(vec!["name", "tags"]), @@ -198,6 +215,40 @@ async fn test_get_all_documents_attributes_to_retrieve() { .count(), 2 ); + + let (response, code) = index + .get_all_documents(GetAllDocumentsOptions { + attributes_to_retrieve: Some(vec!["*"]), + ..Default::default() + }) + .await; + assert_eq!(code, 200); + assert_eq!(response.as_array().unwrap().len(), 20); + assert_eq!( + response.as_array().unwrap()[0] + .as_object() + .unwrap() + .keys() + .count(), + 16 + ); + + let (response, code) = index + .get_all_documents(GetAllDocumentsOptions { + attributes_to_retrieve: Some(vec!["*", "wrong"]), + ..Default::default() + }) + .await; + assert_eq!(code, 200); + assert_eq!(response.as_array().unwrap().len(), 20); + assert_eq!( + response.as_array().unwrap()[0] + .as_object() + .unwrap() + .keys() + .count(), + 16 + ); } #[actix_rt::test]