diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index f0133cde4..7457098cb 100644 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -145,6 +145,12 @@ impl fmt::Debug for Query { trait Context { fn word_docids(&self, word: &str) -> heed::Result>; fn synonyms>(&self, words: &[S]) -> heed::Result>>>; + fn word_documents_count(&self, word: &str) -> heed::Result> { + match self.word_docids(word)? { + Some(rb) => Ok(Some(rb.len())), + None => Ok(None), + } + } } /// The query tree builder is the interface to build a query tree. @@ -158,6 +164,10 @@ impl<'a> Context for QueryTreeBuilder<'a> { self.index.word_docids.get(self.rtxn, word) } + fn word_documents_count(&self, word: &str) -> heed::Result> { + self.index.word_documents_count(self.rtxn, word) + } + fn synonyms>(&self, _words: &[S]) -> heed::Result>>> { Ok(None) } @@ -201,8 +211,8 @@ fn split_best_frequency<'a>(ctx: &impl Context, word: &'a str) -> heed::Result old) {