mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-23 03:37:28 +01:00
feat: Introduce some stats to ease debugging
This commit is contained in:
parent
a147c09b06
commit
e08edc2d6b
@ -44,6 +44,26 @@ impl DocumentsIndex {
|
||||
|
||||
DocumentFieldsIter(iter, end.to_vec())
|
||||
}
|
||||
|
||||
pub fn len(&self) -> Result<usize, rocksdb::Error> {
|
||||
let mut last_document_id = None;
|
||||
let mut count = 0;
|
||||
|
||||
let from = rocksdb::IteratorMode::Start;
|
||||
let iterator = self.0.iterator(from)?;
|
||||
|
||||
for (key, value) in iterator {
|
||||
let slice = key.as_ref().try_into().unwrap();
|
||||
let document_id = DocumentAttrKey::from_be_bytes(slice).document_id;
|
||||
|
||||
if Some(document_id) != last_document_id {
|
||||
last_document_id = Some(document_id);
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(count)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DocumentFieldsIter<'a>(rocksdb::DBIterator<'a>, Vec<u8>);
|
||||
|
@ -15,6 +15,13 @@ use crate::serde::Deserializer;
|
||||
use super::{Error, CustomSettings};
|
||||
use super::{RawIndex, DocumentsAddition, DocumentsDeletion};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct IndexStats {
|
||||
pub number_of_words: usize,
|
||||
pub number_of_documents: usize,
|
||||
pub number_attrs_in_ranked_map: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Index(pub ArcSwap<InnerIndex>);
|
||||
|
||||
@ -48,6 +55,16 @@ impl Index {
|
||||
Ok(index)
|
||||
}
|
||||
|
||||
pub fn stats(&self) -> Result<IndexStats, rocksdb::Error> {
|
||||
let lease = self.0.lease();
|
||||
|
||||
Ok(IndexStats {
|
||||
number_of_words: lease.words.len(),
|
||||
number_of_documents: lease.raw.documents.len()?,
|
||||
number_attrs_in_ranked_map: lease.ranked_map.len(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn query_builder(&self) -> QueryBuilder<IndexLease> {
|
||||
let lease = IndexLease(self.0.lease());
|
||||
QueryBuilder::new(lease)
|
||||
|
@ -9,6 +9,10 @@ use crate::{SchemaAttr, Number};
|
||||
pub struct RankedMap(HashMap<(DocumentId, SchemaAttr), Number>);
|
||||
|
||||
impl RankedMap {
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, document: DocumentId, attribute: SchemaAttr, number: Number) {
|
||||
self.0.insert((document, attribute), number);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user