From 2f561c77f528d3ba44c7b1f71575e86781c42a1b Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 18 Feb 2021 14:35:14 +0100 Subject: [PATCH] Introduce the word documents count method on the index --- milli/src/index.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/milli/src/index.rs b/milli/src/index.rs index f8efa324e..5c5fc9895 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -352,6 +352,17 @@ impl Index { } } + /* word documents count */ + + /// Returns the number of documents ids associated with the given word, + /// it is much faster than deserializing the bitmap and getting the length of it. + pub fn word_documents_count(&self, rtxn: &RoTxn, word: &str) -> anyhow::Result> { + self.word_docids + .remap_data_type::() + .get(rtxn, word) + .map_err(Into::into) + } + /* documents */ /// Returns a [`Vec`] of the requested documents. Returns an error if a document is missing.