mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Implement documents format
document reader transform remove update format support document sequences fix document transform clean transform improve error handling add documents! macro fix transform bug fix tests remove csv dependency Add comments on the transform process replace search cli fmt review edits fix http ui fix clippy warnings Revert "fix clippy warnings" This reverts commit a1ce3cd96e603633dbf43e9e0b12b2453c9c5620. fix review comments remove smallvec in transform loop review edits
This commit is contained in:
parent
94764e5c7c
commit
aa6c5df0bc
25 changed files with 5114 additions and 713 deletions
|
@ -27,6 +27,7 @@ pub trait Distinct {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::HashSet;
|
||||
use std::io::Cursor;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::seq::SliceRandom;
|
||||
|
@ -34,19 +35,20 @@ mod test {
|
|||
use roaring::RoaringBitmap;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::documents::{DocumentBatchBuilder, DocumentBatchReader};
|
||||
use crate::index::tests::TempIndex;
|
||||
use crate::index::Index;
|
||||
use crate::update::{IndexDocumentsMethod, UpdateBuilder, UpdateFormat};
|
||||
use crate::update::{IndexDocumentsMethod, UpdateBuilder};
|
||||
use crate::{DocumentId, FieldId, BEU32};
|
||||
|
||||
static JSON: Lazy<Value> = Lazy::new(generate_json);
|
||||
static JSON: Lazy<Vec<u8>> = Lazy::new(generate_documents);
|
||||
|
||||
fn generate_json() -> Value {
|
||||
fn generate_documents() -> Vec<u8> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_docs = rng.gen_range(10..30);
|
||||
|
||||
let mut documents = Vec::new();
|
||||
|
||||
let mut cursor = Cursor::new(Vec::new());
|
||||
let mut builder = DocumentBatchBuilder::new(&mut cursor).unwrap();
|
||||
let txts = ["Toto", "Titi", "Tata"];
|
||||
let cats = (1..10).map(|i| i.to_string()).collect::<Vec<_>>();
|
||||
let cat_ints = (1..10).collect::<Vec<_>>();
|
||||
|
@ -66,10 +68,11 @@ mod test {
|
|||
"txts": sample_txts[..(rng.gen_range(0..3))],
|
||||
"cat-ints": sample_ints[..(rng.gen_range(0..3))],
|
||||
});
|
||||
documents.push(doc);
|
||||
builder.add_documents(doc).unwrap();
|
||||
}
|
||||
|
||||
Value::Array(documents)
|
||||
builder.finish().unwrap();
|
||||
cursor.into_inner()
|
||||
}
|
||||
|
||||
/// Returns a temporary index populated with random test documents, the FieldId for the
|
||||
|
@ -89,13 +92,15 @@ mod test {
|
|||
let mut addition = builder.index_documents(&mut txn, &index);
|
||||
|
||||
addition.index_documents_method(IndexDocumentsMethod::ReplaceDocuments);
|
||||
addition.update_format(UpdateFormat::Json);
|
||||
addition.execute(JSON.to_string().as_bytes(), |_, _| ()).unwrap();
|
||||
let reader =
|
||||
crate::documents::DocumentBatchReader::from_reader(Cursor::new(&*JSON)).unwrap();
|
||||
addition.execute(reader, |_, _| ()).unwrap();
|
||||
|
||||
let fields_map = index.fields_ids_map(&txn).unwrap();
|
||||
let fid = fields_map.id(&distinct).unwrap();
|
||||
|
||||
let map = (0..JSON.as_array().unwrap().len() as u32).collect();
|
||||
let documents = DocumentBatchReader::from_reader(Cursor::new(&*JSON)).unwrap();
|
||||
let map = (0..documents.len() as u32).collect();
|
||||
|
||||
txn.commit().unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue