Searching for a document that does not exist no longer raises an error

This commit is contained in:
Louis Dureuil 2025-03-12 11:50:39 +01:00
parent 7df5e3f059
commit 60ff1b19a8
No known key found for this signature in database
3 changed files with 17 additions and 10 deletions

View File

@ -384,7 +384,6 @@ UnsupportedMediaType , InvalidRequest , UNSUPPORTED_MEDIA
// Experimental features
VectorEmbeddingError , InvalidRequest , BAD_REQUEST ;
NotFoundSimilarId , InvalidRequest , BAD_REQUEST ;
NotFoundDocumentId , InvalidRequest , BAD_REQUEST ;
InvalidDocumentEditionContext , InvalidRequest , BAD_REQUEST ;
InvalidDocumentEditionFunctionFilter , InvalidRequest , BAD_REQUEST ;
EditDocumentsByFunctionError , InvalidRequest , BAD_REQUEST

View File

@ -1513,11 +1513,9 @@ fn retrieve_documents<S: AsRef<str>>(
let mut candidates = if let Some(ids) = ids {
let external_document_ids = index.external_documents_ids();
let mut candidates = RoaringBitmap::new();
for (index, id) in ids.iter().enumerate() {
for id in ids.iter() {
let Some(docid) = external_document_ids.get(&rtxn, id)? else {
let error = MeilisearchHttpError::DocumentNotFound(id.clone().into_inner());
let msg = format!("In `.ids[{index}]`: {error}");
return Err(ResponseError::from_msg(msg, Code::NotFoundDocumentId));
continue;
};
candidates.insert(docid);
}

View File

@ -687,13 +687,23 @@ async fn get_document_not_found_ids() {
let (response, code) = index.fetch_documents(json!({"ids": ["0", 3, 42] })).await;
let (response2, code2) = index.get_all_documents_raw("?ids=0,3,42").await;
snapshot!(code, @"400 Bad Request");
// the document with id 42 is not in the results since it doesn't exist
// however, no error is raised
snapshot!(code, @"200 OK");
snapshot!(json_string!(response, { ".enqueuedAt" => "[date]" }), @r###"
{
"message": "In `.ids[2]`: Document `42` not found.",
"code": "not_found_document_id",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#not_found_document_id"
"results": [
{
"id": 0,
"color": "red"
},
{
"id": 3
}
],
"offset": 0,
"limit": 20,
"total": 2
}
"###);
assert_eq!(code, code2);