mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-11 23:26:28 +00:00
feat: add the documents fields repartition into stats
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
#[macro_use] extern crate maplit;
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -94,3 +96,67 @@ fn replace_document() {
|
||||
assert_eq!(docs.len(), 1);
|
||||
assert_eq!(index.document(None, docs[0].id).unwrap().as_ref(), Some(&doc2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn database_stats() {
|
||||
let tmp_dir = tempfile::tempdir().unwrap();
|
||||
let database = Database::open(&tmp_dir).unwrap();
|
||||
|
||||
let as_been_updated = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let schema = simple_schema();
|
||||
let index = database.create_index("hello", schema).unwrap();
|
||||
|
||||
let as_been_updated_clone = as_been_updated.clone();
|
||||
index.set_update_callback(move |_| as_been_updated_clone.store(true, Relaxed));
|
||||
|
||||
let doc1 = json!({ "objectId": 123, "title": "hello" });
|
||||
|
||||
let mut addition = index.documents_addition();
|
||||
addition.update_document(&doc1);
|
||||
let update_id = addition.finalize().unwrap();
|
||||
let status = index.update_status_blocking(update_id).unwrap();
|
||||
assert!(as_been_updated.swap(false, Relaxed));
|
||||
assert!(status.result.is_ok());
|
||||
let stats = index.stats().unwrap();
|
||||
let repartition = hashmap!{
|
||||
"objectId".to_string() => 1u64,
|
||||
"title".to_string() => 1u64,
|
||||
};
|
||||
assert_eq!(stats.number_of_documents, 1);
|
||||
assert_eq!(stats.documents_fields_repartition, repartition);
|
||||
|
||||
let doc2 = json!({ "objectId": 456, "title": "world" });
|
||||
|
||||
let mut addition = index.documents_addition();
|
||||
addition.update_document(&doc2);
|
||||
let update_id = addition.finalize().unwrap();
|
||||
let status = index.update_status_blocking(update_id).unwrap();
|
||||
assert!(as_been_updated.swap(false, Relaxed));
|
||||
assert!(status.result.is_ok());
|
||||
let stats = index.stats().unwrap();
|
||||
let repartition = hashmap!{
|
||||
"objectId".to_string() => 2u64,
|
||||
"title".to_string() => 2u64,
|
||||
};
|
||||
assert_eq!(stats.number_of_documents, 2);
|
||||
assert_eq!(stats.documents_fields_repartition, repartition);
|
||||
|
||||
|
||||
let doc3 = json!({ "objectId": 789 });
|
||||
|
||||
let mut addition = index.documents_addition();
|
||||
addition.update_document(&doc3);
|
||||
let update_id = addition.finalize().unwrap();
|
||||
let status = index.update_status_blocking(update_id).unwrap();
|
||||
assert!(as_been_updated.swap(false, Relaxed));
|
||||
assert!(status.result.is_ok());
|
||||
let stats = index.stats().unwrap();
|
||||
let repartition = hashmap!{
|
||||
"objectId".to_string() => 3u64,
|
||||
"title".to_string() => 2u64,
|
||||
};
|
||||
assert_eq!(stats.number_of_documents, 3);
|
||||
assert_eq!(stats.documents_fields_repartition, repartition);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user