From 1aef0e40378817f531c0844fbb7dc7299f543bf5 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 19 Nov 2024 12:02:26 +0100 Subject: [PATCH] documents! macro accepts a single object again --- crates/milli/src/documents/mod.rs | 13 +++++++++++-- crates/milli/src/index.rs | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/milli/src/documents/mod.rs b/crates/milli/src/documents/mod.rs index 2d27fed48..5f6235f9e 100644 --- a/crates/milli/src/documents/mod.rs +++ b/crates/milli/src/documents/mod.rs @@ -151,8 +151,17 @@ macro_rules! documents { ($data:tt) => {{ let documents = serde_json::json!($data); let mut file = tempfile::tempfile().unwrap(); - for document in documents.as_array().unwrap() { - serde_json::to_writer(&mut file, &document).unwrap(); + + match documents { + serde_json::Value::Array(vec) => { + for document in vec { + serde_json::to_writer(&mut file, &document).unwrap(); + } + } + serde_json::Value::Object(document) => { + serde_json::to_writer(&mut file, &document).unwrap(); + } + _ => unimplemented!("The `documents!` macro only support Objects and Array"), } file.sync_all().unwrap(); unsafe { memmap2::Mmap::map(&file).unwrap() } diff --git a/crates/milli/src/index.rs b/crates/milli/src/index.rs index e600739a9..6d832ec18 100644 --- a/crates/milli/src/index.rs +++ b/crates/milli/src/index.rs @@ -1749,7 +1749,8 @@ pub(crate) mod tests { let db_fields_ids_map = self.inner.fields_ids_map(&rtxn)?; let mut new_fields_ids_map = db_fields_ids_map.clone(); - let embedders = EmbeddingConfigs::default(); /// TODO: fetch configs from the index + let embedders = EmbeddingConfigs::default(); + /// TODO: fetch configs from the index let mut indexer = indexer::DocumentOperation::new(IndexDocumentsMethod::ReplaceDocuments); indexer.add_documents(&documents).unwrap();