From d0f048c068403fd146cc98f0e9e76a82915ece8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Thu, 30 Mar 2023 11:08:17 +0200 Subject: [PATCH] Simplify the API of the DatabaseCache --- milli/src/search/new/db_cache.rs | 95 +++++++++++++++----------------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/milli/src/search/new/db_cache.rs b/milli/src/search/new/db_cache.rs index 2fa92900c..af94108e2 100644 --- a/milli/src/search/new/db_cache.rs +++ b/milli/src/search/new/db_cache.rs @@ -5,8 +5,8 @@ use fxhash::FxHashMap; use heed::types::ByteSlice; use heed::{BytesEncode, Database, RoTxn}; -use super::interner::{DedupInterner, Interned}; -use crate::{Index, Result}; +use super::interner::Interned; +use crate::{Result, SearchContext}; /// A cache storing pointers to values in the LMDB databases. /// @@ -47,94 +47,85 @@ impl<'ctx> DatabaseCache<'ctx> { }; Ok(bitmap_ptr) } - +} +impl<'ctx> SearchContext<'ctx> { /// Retrieve or insert the given value in the `word_docids` database. - pub fn get_word_docids( - &mut self, - index: &Index, - txn: &'ctx RoTxn, - word_interner: &DedupInterner, - word: Interned, - ) -> Result> { - Self::get_value( - txn, + pub fn get_db_word_docids(&mut self, word: Interned) -> Result> { + DatabaseCache::get_value( + self.txn, word, - word_interner.get(word).as_str(), - &mut self.word_docids, - index.word_docids.remap_data_type::(), + self.word_interner.get(word).as_str(), + &mut self.db_cache.word_docids, + self.index.word_docids.remap_data_type::(), ) } /// Retrieve or insert the given value in the `word_prefix_docids` database. - pub fn get_word_prefix_docids( + pub fn get_db_word_prefix_docids( &mut self, - index: &Index, - txn: &'ctx RoTxn, - word_interner: &DedupInterner, prefix: Interned, ) -> Result> { - Self::get_value( - txn, + DatabaseCache::get_value( + self.txn, prefix, - word_interner.get(prefix).as_str(), - &mut self.word_prefix_docids, - index.word_prefix_docids.remap_data_type::(), + self.word_interner.get(prefix).as_str(), + &mut self.db_cache.word_prefix_docids, + self.index.word_prefix_docids.remap_data_type::(), ) } - pub fn get_word_pair_proximity_docids( + pub fn get_db_word_pair_proximity_docids( &mut self, - index: &Index, - txn: &'ctx RoTxn, - word_interner: &DedupInterner, word1: Interned, word2: Interned, proximity: u8, ) -> Result> { - Self::get_value( - txn, + DatabaseCache::get_value( + self.txn, (proximity, word1, word2), - &(proximity, word_interner.get(word1).as_str(), word_interner.get(word2).as_str()), - &mut self.word_pair_proximity_docids, - index.word_pair_proximity_docids.remap_data_type::(), + &( + proximity, + self.word_interner.get(word1).as_str(), + self.word_interner.get(word2).as_str(), + ), + &mut self.db_cache.word_pair_proximity_docids, + self.index.word_pair_proximity_docids.remap_data_type::(), ) } - pub fn get_word_prefix_pair_proximity_docids( + pub fn get_db_word_prefix_pair_proximity_docids( &mut self, - index: &Index, - txn: &'ctx RoTxn, - word_interner: &DedupInterner, word1: Interned, prefix2: Interned, proximity: u8, ) -> Result> { - Self::get_value( - txn, + DatabaseCache::get_value( + self.txn, (proximity, word1, prefix2), - &(proximity, word_interner.get(word1).as_str(), word_interner.get(prefix2).as_str()), - &mut self.word_prefix_pair_proximity_docids, - index.word_prefix_pair_proximity_docids.remap_data_type::(), + &( + proximity, + self.word_interner.get(word1).as_str(), + self.word_interner.get(prefix2).as_str(), + ), + &mut self.db_cache.word_prefix_pair_proximity_docids, + self.index.word_prefix_pair_proximity_docids.remap_data_type::(), ) } - pub fn get_prefix_word_pair_proximity_docids( + pub fn get_db_prefix_word_pair_proximity_docids( &mut self, - index: &Index, - txn: &'ctx RoTxn, - word_interner: &DedupInterner, left_prefix: Interned, right: Interned, proximity: u8, ) -> Result> { - Self::get_value( - txn, + DatabaseCache::get_value( + self.txn, (proximity, left_prefix, right), &( proximity, - word_interner.get(left_prefix).as_str(), - word_interner.get(right).as_str(), + self.word_interner.get(left_prefix).as_str(), + self.word_interner.get(right).as_str(), ), - &mut self.prefix_word_pair_proximity_docids, - index.prefix_word_pair_proximity_docids.remap_data_type::(), + &mut self.db_cache.prefix_word_pair_proximity_docids, + self.index.prefix_word_pair_proximity_docids.remap_data_type::(), ) } }