From d61566787eedd64ee5f3e40d1786714893910f16 Mon Sep 17 00:00:00 2001 From: tamo Date: Tue, 4 May 2021 11:23:51 +0200 Subject: [PATCH] provide an iterator over all the documents in a milli index --- milli/src/index.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/milli/src/index.rs b/milli/src/index.rs index 584ffab56..945567cdb 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -477,6 +477,18 @@ impl Index { Ok(documents) } + /// Returns an iterator over all the documents in the index. + pub fn all_documents<'t>( + &self, + rtxn: &'t RoTxn, + ) -> anyhow::Result)>>> { + 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> { FacetDistribution::new(rtxn, self) }