provide an iterator over all the documents in a milli index

This commit is contained in:
tamo 2021-05-04 11:23:51 +02:00
parent c08f4599f2
commit d61566787e
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69

View File

@ -477,6 +477,18 @@ impl Index {
Ok(documents) Ok(documents)
} }
/// Returns an iterator over all the documents in the index.
pub fn all_documents<'t>(
&self,
rtxn: &'t RoTxn,
) -> anyhow::Result<impl Iterator<Item = heed::Result<(DocumentId, obkv::KvReader<'t>)>>> {
Ok(self
.documents
.iter(rtxn)?
// we cast the BEU32 to a DocumentId
.map(|document| document.map(|(id, obkv)| (id.get(), obkv))))
}
pub fn facets_distribution<'a>(&'a self, rtxn: &'a RoTxn) -> FacetDistribution<'a> { pub fn facets_distribution<'a>(&'a self, rtxn: &'a RoTxn) -> FacetDistribution<'a> {
FacetDistribution::new(rtxn, self) FacetDistribution::new(rtxn, self)
} }