Introduce the word documents count method on the index

This commit is contained in:
Kerollmops 2021-02-18 14:35:14 +01:00
parent 8d710c5130
commit 2f561c77f5
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -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<Option<u64>> {
self.word_docids
.remap_data_type::<RoaringBitmapLenCodec>()
.get(rtxn, word)
.map_err(Into::into)
}
/* documents */ /* documents */
/// Returns a [`Vec`] of the requested documents. Returns an error if a document is missing. /// Returns a [`Vec`] of the requested documents. Returns an error if a document is missing.