diff --git a/meilidb-core/src/store/documents_fields_counts.rs b/meilidb-core/src/store/documents_fields_counts.rs index 75b50966e..b68821976 100644 --- a/meilidb-core/src/store/documents_fields_counts.rs +++ b/meilidb-core/src/store/documents_fields_counts.rs @@ -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, 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 { + 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, + } + } +}