mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 12:54:26 +01:00
fix the fields field of the POST fetch document API
This commit is contained in:
parent
ce6507d20c
commit
469d2f2a9c
@ -152,7 +152,7 @@ pub struct BrowseQuery {
|
|||||||
#[deserr(default = PAGINATION_DEFAULT_LIMIT, error = DeserrJsonError<InvalidDocumentGetLimit>)]
|
#[deserr(default = PAGINATION_DEFAULT_LIMIT, error = DeserrJsonError<InvalidDocumentGetLimit>)]
|
||||||
limit: usize,
|
limit: usize,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidDocumentGetFields>)]
|
#[deserr(default, error = DeserrJsonError<InvalidDocumentGetFields>)]
|
||||||
fields: OptionStarOrList<String>,
|
fields: Option<Vec<String>>,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidDocumentGetFilter>)]
|
#[deserr(default, error = DeserrJsonError<InvalidDocumentGetFilter>)]
|
||||||
filter: Option<Value>,
|
filter: Option<Value>,
|
||||||
}
|
}
|
||||||
@ -184,7 +184,12 @@ pub async fn get_documents(
|
|||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = BrowseQuery { offset: offset.0, limit: limit.0, fields, filter };
|
let query = BrowseQuery {
|
||||||
|
offset: offset.0,
|
||||||
|
limit: limit.0,
|
||||||
|
fields: fields.merge_star_and_none(),
|
||||||
|
filter,
|
||||||
|
};
|
||||||
|
|
||||||
documents_by_query(&index_scheduler, index_uid, query)
|
documents_by_query(&index_scheduler, index_uid, query)
|
||||||
}
|
}
|
||||||
@ -196,11 +201,9 @@ fn documents_by_query(
|
|||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
|
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
|
||||||
let BrowseQuery { offset, limit, fields, filter } = query;
|
let BrowseQuery { offset, limit, fields, filter } = query;
|
||||||
let attributes_to_retrieve = fields.merge_star_and_none();
|
|
||||||
|
|
||||||
let index = index_scheduler.index(&index_uid)?;
|
let index = index_scheduler.index(&index_uid)?;
|
||||||
let (total, documents) =
|
let (total, documents) = retrieve_documents(&index, offset, limit, filter, fields)?;
|
||||||
retrieve_documents(&index, offset, limit, filter, attributes_to_retrieve)?;
|
|
||||||
|
|
||||||
let ret = PaginationView::new(offset, limit, total as usize, documents);
|
let ret = PaginationView::new(offset, limit, total as usize, documents);
|
||||||
|
|
||||||
|
@ -726,11 +726,11 @@ async fn fetch_document_by_filter() {
|
|||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
let (response, code) = index.get_document_by_filter(json!({ "fields": ["doggo"] })).await;
|
let (response, code) = index.get_document_by_filter(json!({ "fields": "doggo" })).await;
|
||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(json_string!(response), @r###"
|
snapshot!(json_string!(response), @r###"
|
||||||
{
|
{
|
||||||
"message": "Invalid value type at `.fields`: expected a string, but found an array: `[\"doggo\"]`",
|
"message": "Invalid value type at `.fields`: expected an array, but found a string: `\"doggo\"`",
|
||||||
"code": "invalid_document_get_fields",
|
"code": "invalid_document_get_fields",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#invalid_document_get_fields"
|
"link": "https://docs.meilisearch.com/errors#invalid_document_get_fields"
|
||||||
|
@ -473,7 +473,9 @@ async fn get_document_by_filter() {
|
|||||||
assert_eq!(response, response2);
|
assert_eq!(response, response2);
|
||||||
|
|
||||||
let (response, code) = index
|
let (response, code) = index
|
||||||
.get_document_by_filter(json!({ "limit": 1, "filter": "color != blue", "fields": "color" }))
|
.get_document_by_filter(
|
||||||
|
json!({ "limit": 1, "filter": "color != blue", "fields": ["color"] }),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
let (response2, code2) =
|
let (response2, code2) =
|
||||||
index.get_all_documents_raw("?limit=1&filter=color!=blue&fields=color").await;
|
index.get_all_documents_raw("?limit=1&filter=color!=blue&fields=color").await;
|
||||||
|
Loading…
Reference in New Issue
Block a user