Repository: meilisearch/meilisearch
File: crates/meilisearch/src/routes/indexes/documents.rs (Rust)

Code before:
            max_offset: query.offset,
            max_document_ids: query.ids.as_ref().map(Vec::len).unwrap_or_default(),
            per_document_id: false,
            marker: PhantomData,
        },
        &req,
    );

    documents_by_query(&index_scheduler, index_uid, query)
}

fn documents_by_query(
    index_scheduler: &IndexScheduler,
    index_uid: web::Path<String>,
    query: BrowseQuery,
) -> Result<HttpResponse, ResponseError> {
    let index_uid = IndexUid::try_from(index_uid.into_inner())?;
    let BrowseQuery { offset, limit, fields, retrieve_vectors, filter, ids } = query;

    let retrieve_vectors = RetrieveVectors::new(retrieve_vectors);

    let ids = if let Some(ids) = ids {
        let mut parsed_ids = Vec::with_capacity(ids.len());
        for (index, id) in ids.into_iter().enumerate() {
            let id = id.try_into().map_err(|error| {
                let msg = format!("In `.ids[{index}]`:{error}");
                ResponseError::from_msg(msg, Code::InvalidDocumentIds)
            })?;
            parsed_ids.push(id)
        }
        Some(parsed_ids)
    } else {
        None
    };

    let index = index_scheduler.index(&index_uid)?;
    let (total, documents) = retrieve_documents(
        &index,
        offset,
        limit,
        ids,
        filter,
        fields,
        retrieve_vectors,
        index_scheduler.features(),
    )?;

    let ret = PaginationView::new(offset, limit, total as usize, documents);

    debug!(returns = ?ret, "Get documents");
    Ok(HttpResponse::Ok().json(ret))

Review comment (suggestion):
```suggestion
                let msg = format!("In `.ids[{index}]`: {error}");
```

Code after:
            max_offset: query.offset,
            max_document_ids: query.ids.as_ref().map(Vec::len).unwrap_or_default(),
            per_document_id: false,
            marker: PhantomData,
        },
        &req,
    );

    documents_by_query(&index_scheduler, index_uid, query)
}

fn documents_by_query(
    index_scheduler: &IndexScheduler,
    index_uid: web::Path<String>,
    query: BrowseQuery,
) -> Result<HttpResponse, ResponseError> {
    let index_uid = IndexUid::try_from(index_uid.into_inner())?;
    let BrowseQuery { offset, limit, fields, retrieve_vectors, filter, ids } = query;

    let retrieve_vectors = RetrieveVectors::new(retrieve_vectors);

    let ids = if let Some(ids) = ids {
        let mut parsed_ids = Vec::with_capacity(ids.len());
        for (index, id) in ids.into_iter().enumerate() {
            let id = id.try_into().map_err(|error| {
                let msg = format!("In `.ids[{index}]`: {error}");
                ResponseError::from_msg(msg, Code::InvalidDocumentIds)
            })?;
            parsed_ids.push(id)
        }
        Some(parsed_ids)
    } else {
        None
    };

    let index = index_scheduler.index(&index_uid)?;
    let (total, documents) = retrieve_documents(
        &index,
        offset,
        limit,
        ids,
        filter,
        fields,
        retrieve_vectors,
        index_scheduler.features(),
    )?;

    let ret = PaginationView::new(offset, limit, total as usize, documents);

    debug!(returns = ?ret, "Get documents");
    Ok(HttpResponse::Ok().json(ret))