mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
documents! macro accepts a single object again
This commit is contained in:
parent
2cf5faa0e8
commit
32caf3745e
@ -151,8 +151,17 @@ macro_rules! documents {
|
|||||||
($data:tt) => {{
|
($data:tt) => {{
|
||||||
let documents = serde_json::json!($data);
|
let documents = serde_json::json!($data);
|
||||||
let mut file = tempfile::tempfile().unwrap();
|
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();
|
file.sync_all().unwrap();
|
||||||
unsafe { memmap2::Mmap::map(&file).unwrap() }
|
unsafe { memmap2::Mmap::map(&file).unwrap() }
|
||||||
|
@ -1749,7 +1749,8 @@ pub(crate) mod tests {
|
|||||||
let db_fields_ids_map = self.inner.fields_ids_map(&rtxn)?;
|
let db_fields_ids_map = self.inner.fields_ids_map(&rtxn)?;
|
||||||
let mut new_fields_ids_map = db_fields_ids_map.clone();
|
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 =
|
let mut indexer =
|
||||||
indexer::DocumentOperation::new(IndexDocumentsMethod::ReplaceDocuments);
|
indexer::DocumentOperation::new(IndexDocumentsMethod::ReplaceDocuments);
|
||||||
indexer.add_documents(&documents).unwrap();
|
indexer.add_documents(&documents).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user