Update new search test

This commit is contained in:
Loïc Lecrenier 2023-03-06 10:21:28 +01:00
parent cab2b6bcda
commit 3f1729a17f

View File

@ -328,49 +328,50 @@ mod tests {
println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len()); println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len());
let primary_key = index.primary_key(&txn).unwrap().unwrap();
let primary_key = index.fields_ids_map(&txn).unwrap().id(primary_key).unwrap();
// loop { // loop {
let start = Instant::now(); let start = Instant::now();
let mut db_cache = DatabaseCache::default(); let mut db_cache = DatabaseCache::default();
// let mut logger = crate::new::logger::detailed::DetailedSearchLogger::new("log"); let mut logger = crate::new::logger::detailed::DetailedSearchLogger::new("log");
let results = execute_search( let results = execute_search(
&index, &index,
&txn, &txn,
&mut db_cache, &mut db_cache,
"which a the releases from poison by the government", "releases from poison by the government",
None, None,
0, 0,
20, 20,
&mut DefaultSearchLogger, // &mut DefaultSearchLogger,
// &mut logger, &mut logger,
) )
.unwrap(); .unwrap();
// logger.write_d2_description(); logger.write_d2_description();
let elapsed = start.elapsed(); let elapsed = start.elapsed();
let ids = index let documents = index
.documents(&txn, results.iter().copied()) .documents(&txn, results.iter().copied())
.unwrap() .unwrap()
.into_iter() .into_iter()
.map(|x| { .map(|(id, obkv)| {
let obkv = &x.1; let mut object = serde_json::Map::default();
let id = obkv.get(primary_key).unwrap(); for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() {
let id: serde_json::Value = serde_json::from_slice(id).unwrap(); let value = obkv.get(fid).unwrap();
id.as_str().unwrap().to_owned() let value: serde_json::Value = serde_json::from_slice(value).unwrap();
object.insert(fid_name.to_owned(), value);
}
(id, serde_json::to_string_pretty(&object).unwrap())
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
println!("{}us: {results:?}", elapsed.as_micros()); println!("{}us: {:?}", elapsed.as_micros(), results);
println!("external ids: {ids:?}"); for (id, document) in documents {
// println!("max_resident: {}", ALLOC.max_resident.load(std::sync::atomic::Ordering::SeqCst)); println!("{id}:");
// println!("allocated: {}", ALLOC.allocated.load(std::sync::atomic::Ordering::SeqCst)); println!("{document}");
// } }
} }
#[test] #[test]
@ -385,9 +386,6 @@ mod tests {
let rr = index.criteria(&txn).unwrap(); let rr = index.criteria(&txn).unwrap();
println!("{rr:?}"); println!("{rr:?}");
let primary_key = index.primary_key(&txn).unwrap().unwrap();
let primary_key = index.fields_ids_map(&txn).unwrap().id(primary_key).unwrap();
let start = Instant::now(); let start = Instant::now();
let mut s = Search::new(&txn, &index); let mut s = Search::new(&txn, &index);
@ -398,20 +396,26 @@ mod tests {
let elapsed = start.elapsed(); let elapsed = start.elapsed();
let ids = index let documents = index
.documents(&txn, docs.documents_ids.iter().copied()) .documents(&txn, docs.documents_ids.iter().copied())
.unwrap() .unwrap()
.into_iter() .into_iter()
.map(|x| { .map(|(id, obkv)| {
let obkv = &x.1; let mut object = serde_json::Map::default();
let id = obkv.get(primary_key).unwrap(); for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() {
let id: serde_json::Value = serde_json::from_slice(id).unwrap(); let value = obkv.get(fid).unwrap();
id.as_str().unwrap().to_owned() let value: serde_json::Value = serde_json::from_slice(value).unwrap();
object.insert(fid_name.to_owned(), value);
}
(id, serde_json::to_string_pretty(&object).unwrap())
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
println!("{}us: {:?}", elapsed.as_micros(), docs.documents_ids); println!("{}us: {:?}", elapsed.as_micros(), docs.documents_ids);
println!("external ids: {ids:?}"); for (id, document) in documents {
println!("{id}:");
println!("{document}");
}
} }
#[test] #[test]
fn search_movies_new() { fn search_movies_new() {