mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-05 04:28:55 +01:00
Merge pull request #220 from meilisearch/all-documents-fields-iter
Introduce an Iterator to visit all documents attributes counts
This commit is contained in:
commit
c332c7bc70
@ -80,6 +80,15 @@ impl DocumentsFieldsCounts {
|
||||
let iter = self.documents_fields_counts.iter_start(reader)?;
|
||||
Ok(DocumentsIdsIter { last_seen_id: None, iter })
|
||||
}
|
||||
|
||||
pub fn all_documents_fields_counts<'r, T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &'r T,
|
||||
) -> Result<AllDocumentsFieldsCountsIter<'r>, rkv::StoreError>
|
||||
{
|
||||
let iter = self.documents_fields_counts.iter_start(reader)?;
|
||||
Ok(AllDocumentsFieldsCountsIter { iter })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DocumentFieldsCountsIter<'r> {
|
||||
@ -132,3 +141,24 @@ impl Iterator for DocumentsIdsIter<'_> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AllDocumentsFieldsCountsIter<'r> {
|
||||
iter: rkv::store::single::Iter<'r>,
|
||||
}
|
||||
|
||||
impl<'r> Iterator for AllDocumentsFieldsCountsIter<'r> {
|
||||
type Item = Result<(DocumentId, SchemaAttr, u64), rkv::StoreError>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.iter.next() {
|
||||
Some(Ok((key, Some(rkv::Value::U64(count))))) => {
|
||||
let array = TryFrom::try_from(key).unwrap();
|
||||
let (document_id, attr) = document_attribute_from_key(array);
|
||||
Some(Ok((document_id, attr, count)))
|
||||
},
|
||||
Some(Ok((key, data))) => panic!("{:?}, {:?}", key, data),
|
||||
Some(Err(e)) => Some(Err(e)),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user