Apply review comments

This commit is contained in:
Clément Renault 2024-07-11 11:00:27 +02:00
parent 837274f853
commit 6e80364c50
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
5 changed files with 14 additions and 8 deletions

View File

@ -151,11 +151,14 @@ make_missing_field_convenience_builder!(MissingApiKeyExpiresAt, missing_api_key_
make_missing_field_convenience_builder!(MissingApiKeyIndexes, missing_api_key_indexes);
make_missing_field_convenience_builder!(MissingSwapIndexes, missing_swap_indexes);
make_missing_field_convenience_builder!(MissingDocumentFilter, missing_document_filter);
make_missing_field_convenience_builder!(MissingDocumentFilter, missing_document_edition_function);
make_missing_field_convenience_builder!(
MissingFacetSearchFacetName,
missing_facet_search_facet_name
);
make_missing_field_convenience_builder!(
MissingDocumentEditionFunction,
missing_document_edition_function
);
// Integrate a sub-error into a [`DeserrError`] by taking its error message but using
// the default error code (C) from `Self`

View File

@ -224,6 +224,7 @@ InvalidDocumentCsvDelimiter , InvalidRequest , BAD_REQUEST ;
InvalidDocumentFields , InvalidRequest , BAD_REQUEST ;
InvalidDocumentRetrieveVectors , InvalidRequest , BAD_REQUEST ;
MissingDocumentFilter , InvalidRequest , BAD_REQUEST ;
MissingDocumentEditionFunction , InvalidRequest , BAD_REQUEST ;
InvalidDocumentFilter , InvalidRequest , BAD_REQUEST ;
InvalidDocumentGeoField , InvalidRequest , BAD_REQUEST ;
InvalidVectorDimensions , InvalidRequest , BAD_REQUEST ;

View File

@ -24,7 +24,7 @@ use meilisearch_types::{milli, Document, Index};
use mime::Mime;
use once_cell::sync::Lazy;
use serde::Deserialize;
use serde_json::{Map, Value};
use serde_json::Value;
use tempfile::tempfile;
use tokio::fs::File;
use tokio::io::{AsyncSeekExt, AsyncWriteExt, BufWriter};
@ -629,7 +629,7 @@ pub async fn edit_documents_by_function(
filter_expr: filter,
context: match context {
Some(Value::Object(m)) => Some(m),
None => Some(Map::default()),
None => None,
_ => {
return Err(ResponseError::from_msg(
"The context must be an object".to_string(),

View File

@ -216,11 +216,11 @@ where
let mut documents_batch_builder = tempfile::tempfile().map(DocumentsBatchBuilder::new)?;
let mut documents_to_remove = RoaringBitmap::new();
let context: Dynamic = match context {
let context: Option<Dynamic> = match context {
Some(context) => {
serde_json::from_value(context.into()).map_err(InternalError::SerdeJson)?
Some(serde_json::from_value(context.into()).map_err(InternalError::SerdeJson)?)
}
None => Dynamic::from(()),
None => None,
};
enum DocumentEdition {
@ -244,7 +244,9 @@ where
let document_id = &json_document[primary_key];
let mut scope = Scope::new();
scope.push_constant_dynamic("context", context.clone());
if let Some(context) = context.as_ref().cloned() {
scope.push_constant_dynamic("context", context.clone());
}
scope.push("doc", rhai_document);
// That's were the magic happens. We run the user script
// which edits "doc" scope variable reprensenting the document

View File

@ -60,7 +60,7 @@ impl<'t> ImmutableObkvs<'t> {
let name = self.fields_ids_map.name(id).ok_or(
crate::error::FieldIdMapMissingEntry::FieldId {
field_id: id,
process: "allobkv_to_rhaimap",
process: "all_obkv_to_rhaimap",
},
)?;
let value = serde_json::from_slice(value)