From 14e8d0aaa2f10f72b59f759b7fb98b9f988ab1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Mon, 13 Mar 2023 14:03:48 +0100 Subject: [PATCH] Rename lifetime --- milli/src/search/new/db_cache.rs | 42 ++++---- milli/src/search/new/distinct.rs | 4 +- .../search/new/graph_based_ranking_rule.rs | 36 +++---- milli/src/search/new/interner.rs | 1 + milli/src/search/new/logger/detailed.rs | 5 +- milli/src/search/new/mod.rs | 100 +++++++++--------- milli/src/search/new/query_term.rs | 4 +- .../search/new/ranking_rule_graph/build.rs | 6 ++ .../ranking_rule_graph/edge_docids_cache.rs | 4 +- .../src/search/new/ranking_rule_graph/mod.rs | 73 +++---------- .../new/ranking_rule_graph/proximity/build.rs | 4 +- .../proximity/compute_docids.rs | 4 +- .../new/ranking_rule_graph/proximity/mod.rs | 12 +-- .../search/new/ranking_rule_graph/typo/mod.rs | 12 +-- milli/src/search/new/ranking_rules.rs | 17 +-- milli/src/search/new/resolve_query_graph.rs | 28 ++--- milli/src/search/new/sort.rs | 30 +++--- milli/src/search/new/words.rs | 8 +- 18 files changed, 177 insertions(+), 213 deletions(-) diff --git a/milli/src/search/new/db_cache.rs b/milli/src/search/new/db_cache.rs index 8435eb9da..b1f57fd0e 100644 --- a/milli/src/search/new/db_cache.rs +++ b/milli/src/search/new/db_cache.rs @@ -14,25 +14,25 @@ use crate::{Index, Result}; /// database lookup and instead get a direct reference to the value using a fast /// local HashMap lookup. #[derive(Default)] -pub struct DatabaseCache<'search> { +pub struct DatabaseCache<'ctx> { pub word_pair_proximity_docids: - FxHashMap<(u8, Interned, Interned), Option<&'search [u8]>>, + FxHashMap<(u8, Interned, Interned), Option<&'ctx [u8]>>, pub word_prefix_pair_proximity_docids: - FxHashMap<(u8, Interned, Interned), Option<&'search [u8]>>, + FxHashMap<(u8, Interned, Interned), Option<&'ctx [u8]>>, pub prefix_word_pair_proximity_docids: - FxHashMap<(u8, Interned, Interned), Option<&'search [u8]>>, - pub word_docids: FxHashMap, Option<&'search [u8]>>, - pub exact_word_docids: FxHashMap, Option<&'search [u8]>>, - pub word_prefix_docids: FxHashMap, Option<&'search [u8]>>, + FxHashMap<(u8, Interned, Interned), Option<&'ctx [u8]>>, + pub word_docids: FxHashMap, Option<&'ctx [u8]>>, + pub exact_word_docids: FxHashMap, Option<&'ctx [u8]>>, + pub word_prefix_docids: FxHashMap, Option<&'ctx [u8]>>, } -impl<'search> DatabaseCache<'search> { +impl<'ctx> DatabaseCache<'ctx> { fn get_value<'v, K1, KC>( - txn: &'search RoTxn, + txn: &'ctx RoTxn, cache_key: K1, db_key: &'v KC::EItem, - cache: &mut FxHashMap>, + cache: &mut FxHashMap>, db: Database, - ) -> Result> + ) -> Result> where K1: Copy + Eq + Hash, KC: BytesEncode<'v>, @@ -52,10 +52,10 @@ impl<'search> DatabaseCache<'search> { pub fn get_word_docids( &mut self, index: &Index, - txn: &'search RoTxn, + txn: &'ctx RoTxn, word_interner: &Interner, word: Interned, - ) -> Result> { + ) -> Result> { Self::get_value( txn, word, @@ -68,10 +68,10 @@ impl<'search> DatabaseCache<'search> { pub fn get_word_prefix_docids( &mut self, index: &Index, - txn: &'search RoTxn, + txn: &'ctx RoTxn, word_interner: &Interner, prefix: Interned, - ) -> Result> { + ) -> Result> { Self::get_value( txn, prefix, @@ -84,12 +84,12 @@ impl<'search> DatabaseCache<'search> { pub fn get_word_pair_proximity_docids( &mut self, index: &Index, - txn: &'search RoTxn, + txn: &'ctx RoTxn, word_interner: &Interner, word1: Interned, word2: Interned, proximity: u8, - ) -> Result> { + ) -> Result> { Self::get_value( txn, (proximity, word1, word2), @@ -102,12 +102,12 @@ impl<'search> DatabaseCache<'search> { pub fn get_word_prefix_pair_proximity_docids( &mut self, index: &Index, - txn: &'search RoTxn, + txn: &'ctx RoTxn, word_interner: &Interner, word1: Interned, prefix2: Interned, proximity: u8, - ) -> Result> { + ) -> Result> { Self::get_value( txn, (proximity, word1, prefix2), @@ -119,12 +119,12 @@ impl<'search> DatabaseCache<'search> { pub fn get_prefix_word_pair_proximity_docids( &mut self, index: &Index, - txn: &'search RoTxn, + txn: &'ctx RoTxn, word_interner: &Interner, left_prefix: Interned, right: Interned, proximity: u8, - ) -> Result> { + ) -> Result> { Self::get_value( txn, (proximity, left_prefix, right), diff --git a/milli/src/search/new/distinct.rs b/milli/src/search/new/distinct.rs index 9ee1746df..b29f0e8c3 100644 --- a/milli/src/search/new/distinct.rs +++ b/milli/src/search/new/distinct.rs @@ -20,8 +20,8 @@ pub struct DistinctOutput { pub excluded: RoaringBitmap, } -pub fn apply_distinct_rule<'search>( - ctx: &mut SearchContext<'search>, +pub fn apply_distinct_rule<'ctx>( + ctx: &mut SearchContext<'ctx>, field_id: u16, candidates: &RoaringBitmap, ) -> Result { diff --git a/milli/src/search/new/graph_based_ranking_rule.rs b/milli/src/search/new/graph_based_ranking_rule.rs index 9af41b322..3281ffd2b 100644 --- a/milli/src/search/new/graph_based_ranking_rule.rs +++ b/milli/src/search/new/graph_based_ranking_rule.rs @@ -92,8 +92,8 @@ pub struct GraphBasedRankingRuleState { /// Traverse each edge of the graph, computes its associated document ids, /// and remove this edge from the graph if its docids are disjoint with the /// given universe. -fn remove_empty_edges<'search, G: RankingRuleGraphTrait>( - ctx: &mut SearchContext<'search>, +fn remove_empty_edges<'ctx, G: RankingRuleGraphTrait>( + ctx: &mut SearchContext<'ctx>, graph: &mut RankingRuleGraph, edge_docids_cache: &mut EdgeConditionsCache, universe: &RoaringBitmap, @@ -121,15 +121,13 @@ fn remove_empty_edges<'search, G: RankingRuleGraphTrait>( Ok(()) } -impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph> - for GraphBasedRankingRule -{ +impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBasedRankingRule { fn id(&self) -> String { self.id.clone() } fn start_iteration( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, universe: &RoaringBitmap, query_graph: &QueryGraph, @@ -166,7 +164,7 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph> fn next_bucket( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, logger: &mut dyn SearchLogger, universe: &RoaringBitmap, ) -> Result>> { @@ -210,11 +208,11 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph> cur_distance_idx: _, } = &mut state; - // let original_universe = universe; + let original_universe = universe; let mut universe = universe.clone(); // TODO: remove this unnecessary clone - // let original_graph = graph.clone(); + let original_graph = graph.clone(); // and this vector as well let mut paths = vec![]; @@ -297,15 +295,15 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph> }, )?; - // G::log_state( - // &original_graph, - // &paths, - // &state.empty_paths_cache, - // original_universe, - // &state.all_distances, - // cost, - // logger, - // ); + G::log_state( + &original_graph, + &paths, + &state.empty_paths_cache, + original_universe, + &state.all_distances, + cost, + logger, + ); // TODO: Graph-based ranking rules do not (yet) modify the query graph. We could, however, // remove nodes and/or terms within nodes that weren't present in any of the paths. @@ -318,7 +316,7 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph> fn end_iteration( &mut self, - _ctx: &mut SearchContext<'search>, + _ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, ) { self.state = None; diff --git a/milli/src/search/new/interner.rs b/milli/src/search/new/interner.rs index 7edef41c8..55c343cd5 100644 --- a/milli/src/search/new/interner.rs +++ b/milli/src/search/new/interner.rs @@ -33,6 +33,7 @@ impl Interned { /// is then identified by a lightweight index of type [`Interned`], which can /// be copied, compared, and hashed efficiently. An immutable reference to the original value /// can be retrieved using `self.get(interned)`. +#[derive(Clone)] pub struct Interner { stable_store: Vec, lookup: FxHashMap>, diff --git a/milli/src/search/new/logger/detailed.rs b/milli/src/search/new/logger/detailed.rs index ba443752d..c049e7c17 100644 --- a/milli/src/search/new/logger/detailed.rs +++ b/milli/src/search/new/logger/detailed.rs @@ -545,12 +545,13 @@ shape: class" ) .unwrap(); } - EdgeCondition::Conditional(details) => { + EdgeCondition::Conditional(condition) => { + let condition = graph.conditions_interner.get(*condition); writeln!( file, "{source_node} -> {dest_node} : \"cost {cost} {edge_label}\"", cost = edge.cost, - edge_label = R::label_for_edge_condition(details) + edge_label = R::label_for_edge_condition(condition) ) .unwrap(); } diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index 110cfad64..03b2845cd 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -35,17 +35,17 @@ use crate::search::new::query_term::located_query_terms_from_string; use crate::search::new::words::Words; use crate::{Filter, Index, Result, TermsMatchingStrategy}; -pub struct SearchContext<'search> { - pub index: &'search Index, - pub txn: &'search RoTxn<'search>, - pub db_cache: DatabaseCache<'search>, +pub struct SearchContext<'ctx> { + pub index: &'ctx Index, + pub txn: &'ctx RoTxn<'ctx>, + pub db_cache: DatabaseCache<'ctx>, pub word_interner: Interner, pub phrase_interner: Interner, pub derivations_interner: Interner, pub query_term_docids: QueryTermDocIdsCache, } -impl<'search> SearchContext<'search> { - pub fn new(index: &'search Index, txn: &'search RoTxn<'search>) -> Self { +impl<'ctx> SearchContext<'ctx> { + pub fn new(index: &'ctx Index, txn: &'ctx RoTxn<'ctx>) -> Self { Self { index, txn, @@ -59,8 +59,8 @@ impl<'search> SearchContext<'search> { } #[allow(clippy::too_many_arguments)] -fn resolve_maximally_reduced_query_graph<'search>( - ctx: &mut SearchContext<'search>, +fn resolve_maximally_reduced_query_graph<'ctx>( + ctx: &mut SearchContext<'ctx>, universe: &RoaringBitmap, query_graph: &QueryGraph, matching_strategy: TermsMatchingStrategy, @@ -99,9 +99,9 @@ fn resolve_maximally_reduced_query_graph<'search>( Ok(docids) } -fn get_ranking_rules_for_placeholder_search<'search>( - ctx: &SearchContext<'search>, -) -> Result>>> { +fn get_ranking_rules_for_placeholder_search<'ctx>( + ctx: &SearchContext<'ctx>, +) -> Result>>> { // let sort = false; // let mut asc = HashSet::new(); // let mut desc = HashSet::new(); @@ -122,10 +122,10 @@ fn get_ranking_rules_for_placeholder_search<'search>( } Ok(ranking_rules) } -fn get_ranking_rules_for_query_graph_search<'search>( - ctx: &SearchContext<'search>, +fn get_ranking_rules_for_query_graph_search<'ctx>( + ctx: &SearchContext<'ctx>, terms_matching_strategy: TermsMatchingStrategy, -) -> Result>>> { +) -> Result>>> { // query graph search let mut words = false; let mut typo = false; @@ -215,8 +215,8 @@ fn get_ranking_rules_for_query_graph_search<'search>( } #[allow(clippy::too_many_arguments)] -pub fn execute_search<'search>( - ctx: &mut SearchContext<'search>, +pub fn execute_search<'ctx>( + ctx: &mut SearchContext<'ctx>, query: &str, terms_matching_strategy: TermsMatchingStrategy, filters: Option, @@ -295,45 +295,45 @@ mod tests { println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len()); - // loop { - let start = Instant::now(); + loop { + let start = Instant::now(); - let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log"); - let mut ctx = SearchContext::new(&index, &txn); - let results = execute_search( - &mut ctx, - "zero config", - TermsMatchingStrategy::Last, - None, - 0, - 20, - &mut DefaultSearchLogger, - &mut logger, - ) - .unwrap(); + // let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log"); + let mut ctx = SearchContext::new(&index, &txn); + let results = execute_search( + &mut ctx, + "zero config", + TermsMatchingStrategy::Last, + None, + 0, + 20, + &mut DefaultSearchLogger, + &mut DefaultSearchLogger, + ) + .unwrap(); - logger.write_d2_description(&mut ctx); + // logger.write_d2_description(&mut ctx); - let elapsed = start.elapsed(); - println!("{}us", elapsed.as_micros()); + let elapsed = start.elapsed(); + println!("{}us", elapsed.as_micros()); - let _documents = index - .documents(&txn, results.iter().copied()) - .unwrap() - .into_iter() - .map(|(id, obkv)| { - let mut object = serde_json::Map::default(); - for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() { - let value = obkv.get(fid).unwrap(); - let value: serde_json::Value = serde_json::from_slice(value).unwrap(); - object.insert(fid_name.to_owned(), value); - } - (id, serde_json::to_string_pretty(&object).unwrap()) - }) - .collect::>(); + let _documents = index + .documents(&txn, results.iter().copied()) + .unwrap() + .into_iter() + .map(|(id, obkv)| { + let mut object = serde_json::Map::default(); + for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() { + let value = obkv.get(fid).unwrap(); + let value: serde_json::Value = serde_json::from_slice(value).unwrap(); + object.insert(fid_name.to_owned(), value); + } + (id, serde_json::to_string_pretty(&object).unwrap()) + }) + .collect::>(); - println!("{}us: {:?}", elapsed.as_micros(), results); - // } + println!("{}us: {:?}", elapsed.as_micros(), results); + } // for (id, _document) in documents { // println!("{id}:"); // // println!("{document}"); diff --git a/milli/src/search/new/query_term.rs b/milli/src/search/new/query_term.rs index 5fffe6653..c55a8d44e 100644 --- a/milli/src/search/new/query_term.rs +++ b/milli/src/search/new/query_term.rs @@ -276,8 +276,8 @@ impl LocatedQueryTerm { } /// Convert the tokenised search query into a list of located query terms. -pub fn located_query_terms_from_string<'search>( - ctx: &mut SearchContext<'search>, +pub fn located_query_terms_from_string<'ctx>( + ctx: &mut SearchContext<'ctx>, query: NormalizedTokenIter>, words_limit: Option, ) -> Result> { diff --git a/milli/src/search/new/ranking_rule_graph/build.rs b/milli/src/search/new/ranking_rule_graph/build.rs index 3393f086a..7b00fc445 100644 --- a/milli/src/search/new/ranking_rule_graph/build.rs +++ b/milli/src/search/new/ranking_rule_graph/build.rs @@ -7,6 +7,12 @@ use crate::search::new::{QueryGraph, SearchContext}; use crate::Result; impl RankingRuleGraph { + // TODO: here, the docids of all the edges should already be computed! + // an edge condition would then be reduced to a (ptr to) a roaring bitmap? + // we could build fewer of them by directly comparing them with the universe + // (e.g. for each word pairs?) with `deserialize_within_universe` maybe + // + /// Build the ranking rule graph from the given query graph pub fn build(ctx: &mut SearchContext, query_graph: QueryGraph) -> Result { let QueryGraph { nodes: graph_nodes, edges: graph_edges, .. } = &query_graph; diff --git a/milli/src/search/new/ranking_rule_graph/edge_docids_cache.rs b/milli/src/search/new/ranking_rule_graph/edge_docids_cache.rs index 416ededc0..5da3de326 100644 --- a/milli/src/search/new/ranking_rule_graph/edge_docids_cache.rs +++ b/milli/src/search/new/ranking_rule_graph/edge_docids_cache.rs @@ -24,9 +24,9 @@ impl EdgeConditionsCache { /// /// If the cache does not yet contain these docids, they are computed /// and inserted in the cache. - pub fn get_edge_docids<'s, 'search>( + pub fn get_edge_docids<'s, 'ctx>( &'s mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, // TODO: should be Interned interned_edge_condition: Interned, graph: &RankingRuleGraph, diff --git a/milli/src/search/new/ranking_rule_graph/mod.rs b/milli/src/search/new/ranking_rule_graph/mod.rs index 8aa29a8b7..16c75b072 100644 --- a/milli/src/search/new/ranking_rule_graph/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/mod.rs @@ -69,47 +69,6 @@ pub struct Edge { pub condition: EdgeCondition, } -// pub struct SubWordDerivations { -// words: FxHashSet>, -// phrases: FxHashSet>, -// use_prefix_db: bool, -// } - -// pub struct EdgeWordDerivations { -// // TODO: not Option, instead: Any | All | Subset(SubWordDerivations) -// from_words: Option, // ??? -// to_words: Option, // + use prefix db? -// } - -// fn aggregate_edge_word_derivations( -// graph: (), -// edges: Vec, -// ) -> BTreeMap { -// todo!() -// } - -// fn reduce_word_term_to_sub_word_derivations( -// term: &mut WordDerivations, -// derivations: &SubWordDerivations, -// ) { -// let mut new_one_typo = vec![]; -// for w in term.one_typo { -// if derivations.words.contains(w) { -// new_one_typo.push(w); -// } -// } -// if term.use_prefix_db && !derivations.use_prefix_db { -// term.use_prefix_db = false; -// } -// // etc. -// } - -// fn word_derivations_used_by_edge( -// edge: G::EdgeCondition, -// ) -> SubWordDerivations { -// todo!() -// } - /// A trait to be implemented by a marker type to build a graph-based ranking rule. /// /// It mostly describes how to: @@ -132,8 +91,8 @@ pub trait RankingRuleGraphTrait: Sized { /// Compute the document ids associated with the given edge condition, /// restricted to the given universe. - fn resolve_edge_condition<'search>( - ctx: &mut SearchContext<'search>, + fn resolve_edge_condition<'ctx>( + ctx: &mut SearchContext<'ctx>, edge_condition: &Self::EdgeCondition, universe: &RoaringBitmap, ) -> Result; @@ -142,15 +101,15 @@ pub trait RankingRuleGraphTrait: Sized { /// /// This call is followed by zero, one or more calls to [`build_step_visit_destination_node`](RankingRuleGraphTrait::build_step_visit_destination_node), /// which builds the actual edges. - fn build_step_visit_source_node<'search>( - ctx: &mut SearchContext<'search>, + fn build_step_visit_source_node<'ctx>( + ctx: &mut SearchContext<'ctx>, source_node: &QueryNode, ) -> Result>; /// Return the cost and condition of the edges going from the previously visited node /// (with [`build_step_visit_source_node`](RankingRuleGraphTrait::build_step_visit_source_node)) to `dest_node`. - fn build_step_visit_destination_node<'from_data, 'search: 'from_data>( - ctx: &mut SearchContext<'search>, + fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>( + ctx: &mut SearchContext<'ctx>, conditions_interner: &mut Interner, dest_node: &QueryNode, source_node_data: &'from_data Self::BuildVisitedFromNode, @@ -177,16 +136,16 @@ pub struct RankingRuleGraph { pub edges_of_node: Vec, pub conditions_interner: Interner, } -// impl Clone for RankingRuleGraph { -// fn clone(&self) -> Self { -// Self { -// query_graph: self.query_graph.clone(), -// edges_store: self.edges_store.clone(), -// edges_of_node: self.edges_of_node.clone(), -// conditions_interner: self.conditions_interner.clone(), -// } -// } -// } +impl Clone for RankingRuleGraph { + fn clone(&self) -> Self { + Self { + query_graph: self.query_graph.clone(), + edges_store: self.edges_store.clone(), + edges_of_node: self.edges_of_node.clone(), + conditions_interner: self.conditions_interner.clone(), + } + } +} impl RankingRuleGraph { /// Remove the given edge from the ranking rule graph pub fn remove_ranking_rule_edge(&mut self, edge_index: u16) { diff --git a/milli/src/search/new/ranking_rule_graph/proximity/build.rs b/milli/src/search/new/ranking_rule_graph/proximity/build.rs index 192b74faf..87cb75e45 100644 --- a/milli/src/search/new/ranking_rule_graph/proximity/build.rs +++ b/milli/src/search/new/ranking_rule_graph/proximity/build.rs @@ -58,8 +58,8 @@ pub fn visit_from_node( })) } -pub fn visit_to_node<'search, 'from_data>( - ctx: &mut SearchContext<'search>, +pub fn visit_to_node<'ctx, 'from_data>( + ctx: &mut SearchContext<'ctx>, conditions_interner: &mut Interner, to_node: &QueryNode, from_node_data: &'from_data (WordDerivations, i8), diff --git a/milli/src/search/new/ranking_rule_graph/proximity/compute_docids.rs b/milli/src/search/new/ranking_rule_graph/proximity/compute_docids.rs index 777d69b64..0821cd5d0 100644 --- a/milli/src/search/new/ranking_rule_graph/proximity/compute_docids.rs +++ b/milli/src/search/new/ranking_rule_graph/proximity/compute_docids.rs @@ -4,8 +4,8 @@ use super::{ProximityEdge, WordPair}; use crate::search::new::SearchContext; use crate::{CboRoaringBitmapCodec, Result}; -pub fn compute_docids<'search>( - ctx: &mut SearchContext<'search>, +pub fn compute_docids<'ctx>( + ctx: &mut SearchContext<'ctx>, edge: &ProximityEdge, universe: &RoaringBitmap, ) -> Result { diff --git a/milli/src/search/new/ranking_rule_graph/proximity/mod.rs b/milli/src/search/new/ranking_rule_graph/proximity/mod.rs index 822c9531c..b099e79f6 100644 --- a/milli/src/search/new/ranking_rule_graph/proximity/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/proximity/mod.rs @@ -36,23 +36,23 @@ impl RankingRuleGraphTrait for ProximityGraph { format!(", prox {proximity}, {} pairs", pairs.len()) } - fn resolve_edge_condition<'search>( - ctx: &mut SearchContext<'search>, + fn resolve_edge_condition<'ctx>( + ctx: &mut SearchContext<'ctx>, edge: &Self::EdgeCondition, universe: &RoaringBitmap, ) -> Result { compute_docids::compute_docids(ctx, edge, universe) } - fn build_step_visit_source_node<'search>( - ctx: &mut SearchContext<'search>, + fn build_step_visit_source_node<'ctx>( + ctx: &mut SearchContext<'ctx>, from_node: &QueryNode, ) -> Result> { build::visit_from_node(ctx, from_node) } - fn build_step_visit_destination_node<'from_data, 'search: 'from_data>( - ctx: &mut SearchContext<'search>, + fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>( + ctx: &mut SearchContext<'ctx>, conditions_interner: &mut Interner, to_node: &QueryNode, from_node_data: &'from_data Self::BuildVisitedFromNode, diff --git a/milli/src/search/new/ranking_rule_graph/typo/mod.rs b/milli/src/search/new/ranking_rule_graph/typo/mod.rs index 596fbfb64..ae5c850e3 100644 --- a/milli/src/search/new/ranking_rule_graph/typo/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/typo/mod.rs @@ -28,8 +28,8 @@ impl RankingRuleGraphTrait for TypoGraph { } } - fn resolve_edge_condition<'db_cache, 'search>( - ctx: &mut SearchContext<'search>, + fn resolve_edge_condition<'db_cache, 'ctx>( + ctx: &mut SearchContext<'ctx>, edge: &Self::EdgeCondition, universe: &RoaringBitmap, ) -> Result { @@ -69,15 +69,15 @@ impl RankingRuleGraphTrait for TypoGraph { } } - fn build_step_visit_source_node<'search>( - _ctx: &mut SearchContext<'search>, + fn build_step_visit_source_node<'ctx>( + _ctx: &mut SearchContext<'ctx>, _from_node: &QueryNode, ) -> Result> { Ok(Some(())) } - fn build_step_visit_destination_node<'from_data, 'search: 'from_data>( - ctx: &mut SearchContext<'search>, + fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>( + ctx: &mut SearchContext<'ctx>, conditions_interner: &mut Interner, to_node: &QueryNode, _from_node_data: &'from_data Self::BuildVisitedFromNode, diff --git a/milli/src/search/new/ranking_rules.rs b/milli/src/search/new/ranking_rules.rs index 57817fd7e..5e5da8716 100644 --- a/milli/src/search/new/ranking_rules.rs +++ b/milli/src/search/new/ranking_rules.rs @@ -17,10 +17,10 @@ impl RankingRuleQueryTrait for QueryGraph {} /// A trait that must be implemented by all ranking rules. /// -/// It is generic over `'search`, the lifetime of the search context +/// It is generic over `'ctx`, the lifetime of the search context /// (i.e. the read transaction and the cache) and over `Query`, which /// can be either [`PlaceholderQuery`] or [`QueryGraph`]. -pub trait RankingRule<'search, Query: RankingRuleQueryTrait> { +pub trait RankingRule<'ctx, Query: RankingRuleQueryTrait> { fn id(&self) -> String; /// Prepare the ranking rule such that it can start iterating over its @@ -29,7 +29,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> { /// The given universe is the universe that will be given to [`next_bucket`](RankingRule::next_bucket). fn start_iteration( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, logger: &mut dyn SearchLogger, universe: &RoaringBitmap, query: &Query, @@ -44,7 +44,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> { /// - the universe given to [`start_iteration`](RankingRule::start_iteration) fn next_bucket( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, logger: &mut dyn SearchLogger, universe: &RoaringBitmap, ) -> Result>>; @@ -53,7 +53,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> { /// The next call to this ranking rule, if any, will be [`start_iteration`](RankingRule::start_iteration). fn end_iteration( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, logger: &mut dyn SearchLogger, ); } @@ -68,15 +68,16 @@ pub struct RankingRuleOutput { pub candidates: RoaringBitmap, } -pub fn bucket_sort<'search, Q: RankingRuleQueryTrait>( - ctx: &mut SearchContext<'search>, - mut ranking_rules: Vec>>, +pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( + ctx: &mut SearchContext<'ctx>, + mut ranking_rules: Vec>>, query: &Q, universe: &RoaringBitmap, from: usize, length: usize, logger: &mut dyn SearchLogger, ) -> Result> { + logger.initial_query(query); logger.ranking_rules(&ranking_rules); logger.initial_universe(universe); diff --git a/milli/src/search/new/resolve_query_graph.rs b/milli/src/search/new/resolve_query_graph.rs index b70b01c34..2553f42c9 100644 --- a/milli/src/search/new/resolve_query_graph.rs +++ b/milli/src/search/new/resolve_query_graph.rs @@ -21,11 +21,11 @@ pub struct QueryTermDocIdsCache { } impl QueryTermDocIdsCache { /// Get the document ids associated with the given phrase - pub fn get_phrase_docids<'s, 'search>( + pub fn get_phrase_docids<'s, 'ctx>( &'s mut self, index: &Index, - txn: &'search RoTxn, - db_cache: &mut DatabaseCache<'search>, + txn: &'ctx RoTxn, + db_cache: &mut DatabaseCache<'ctx>, word_interner: &Interner, phrase_interner: &Interner, phrase: Interned, @@ -40,11 +40,11 @@ impl QueryTermDocIdsCache { } /// Get the document ids associated with the given word derivations - pub fn get_word_derivations_docids<'s, 'search>( + pub fn get_word_derivations_docids<'s, 'ctx>( &'s mut self, index: &Index, - txn: &'search RoTxn, - db_cache: &mut DatabaseCache<'search>, + txn: &'ctx RoTxn, + db_cache: &mut DatabaseCache<'ctx>, word_interner: &Interner, derivations_interner: &Interner, phrase_interner: &Interner, @@ -110,11 +110,11 @@ impl QueryTermDocIdsCache { } /// Get the document ids associated with the given query term. - fn get_query_term_docids<'s, 'search>( + fn get_query_term_docids<'s, 'ctx>( &'s mut self, index: &Index, - txn: &'search RoTxn, - db_cache: &mut DatabaseCache<'search>, + txn: &'ctx RoTxn, + db_cache: &mut DatabaseCache<'ctx>, word_interner: &Interner, derivations_interner: &Interner, phrase_interner: &Interner, @@ -137,8 +137,8 @@ impl QueryTermDocIdsCache { } } -pub fn resolve_query_graph<'search>( - ctx: &mut SearchContext<'search>, +pub fn resolve_query_graph<'ctx>( + ctx: &mut SearchContext<'ctx>, q: &QueryGraph, universe: &RoaringBitmap, ) -> Result { @@ -214,10 +214,10 @@ pub fn resolve_query_graph<'search>( panic!() } -pub fn resolve_phrase<'search>( +pub fn resolve_phrase<'ctx>( index: &Index, - txn: &'search RoTxn, - db_cache: &mut DatabaseCache<'search>, + txn: &'ctx RoTxn, + db_cache: &mut DatabaseCache<'ctx>, word_interner: &Interner, phrase_interner: &Interner, phrase: Interned, diff --git a/milli/src/search/new/sort.rs b/milli/src/search/new/sort.rs index e43a9e8aa..70173889e 100644 --- a/milli/src/search/new/sort.rs +++ b/milli/src/search/new/sort.rs @@ -3,21 +3,19 @@ use roaring::RoaringBitmap; use super::logger::SearchLogger; use super::{RankingRule, RankingRuleOutput, RankingRuleQueryTrait, SearchContext}; -pub trait RankingRuleOutputIter<'search, Query> { +pub trait RankingRuleOutputIter<'ctx, Query> { fn next_bucket(&mut self) -> Result>>; } -pub struct RankingRuleOutputIterWrapper<'search, Query> { - iter: Box>> + 'search>, +pub struct RankingRuleOutputIterWrapper<'ctx, Query> { + iter: Box>> + 'ctx>, } -impl<'search, Query> RankingRuleOutputIterWrapper<'search, Query> { - pub fn new(iter: Box>> + 'search>) -> Self { +impl<'ctx, Query> RankingRuleOutputIterWrapper<'ctx, Query> { + pub fn new(iter: Box>> + 'ctx>) -> Self { Self { iter } } } -impl<'search, Query> RankingRuleOutputIter<'search, Query> - for RankingRuleOutputIterWrapper<'search, Query> -{ +impl<'ctx, Query> RankingRuleOutputIter<'ctx, Query> for RankingRuleOutputIterWrapper<'ctx, Query> { fn next_bucket(&mut self) -> Result>> { match self.iter.next() { Some(x) => x.map(Some), @@ -35,17 +33,17 @@ use crate::{ Result, }; -pub struct Sort<'search, Query> { +pub struct Sort<'ctx, Query> { field_name: String, field_id: Option, is_ascending: bool, original_query: Option, - iter: Option>, + iter: Option>, } -impl<'search, Query> Sort<'search, Query> { +impl<'ctx, Query> Sort<'ctx, Query> { pub fn _new( index: &Index, - rtxn: &'search heed::RoTxn, + rtxn: &'ctx heed::RoTxn, field_name: String, is_ascending: bool, ) -> Result { @@ -56,14 +54,14 @@ impl<'search, Query> Sort<'search, Query> { } } -impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort<'search, Query> { +impl<'ctx, Query: RankingRuleQueryTrait> RankingRule<'ctx, Query> for Sort<'ctx, Query> { fn id(&self) -> String { let Self { field_name, is_ascending, .. } = self; format!("{field_name}:{}", if *is_ascending { "asc" } else { "desc " }) } fn start_iteration( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, parent_candidates: &RoaringBitmap, parent_query_graph: &Query, @@ -106,7 +104,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort fn next_bucket( &mut self, - _ctx: &mut SearchContext<'search>, + _ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, universe: &RoaringBitmap, ) -> Result>> { @@ -123,7 +121,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort fn end_iteration( &mut self, - _ctx: &mut SearchContext<'search>, + _ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, ) { self.original_query = None; diff --git a/milli/src/search/new/words.rs b/milli/src/search/new/words.rs index 2015367da..5bc5ff1fe 100644 --- a/milli/src/search/new/words.rs +++ b/milli/src/search/new/words.rs @@ -26,13 +26,13 @@ impl Words { } } -impl<'search> RankingRule<'search, QueryGraph> for Words { +impl<'ctx> RankingRule<'ctx, QueryGraph> for Words { fn id(&self) -> String { "words".to_owned() } fn start_iteration( &mut self, - _ctx: &mut SearchContext<'search>, + _ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, _parent_candidates: &RoaringBitmap, parent_query_graph: &QueryGraph, @@ -65,7 +65,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words { fn next_bucket( &mut self, - ctx: &mut SearchContext<'search>, + ctx: &mut SearchContext<'ctx>, logger: &mut dyn SearchLogger, universe: &RoaringBitmap, ) -> Result>> { @@ -101,7 +101,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words { fn end_iteration( &mut self, - _ctx: &mut SearchContext<'search>, + _ctx: &mut SearchContext<'ctx>, _logger: &mut dyn SearchLogger, ) { self.iterating = false;