diff --git a/milli/src/search/new/graph_based_ranking_rule.rs b/milli/src/search/new/graph_based_ranking_rule.rs index 72c839f2a..bbe4099bc 100644 --- a/milli/src/search/new/graph_based_ranking_rule.rs +++ b/milli/src/search/new/graph_based_ranking_rule.rs @@ -45,7 +45,7 @@ use super::interner::MappedInterner; use super::logger::SearchLogger; use super::query_graph::QueryNode; use super::ranking_rule_graph::{ - DeadEndPathCache, EdgeConditionDocIdsCache, ProximityGraph, RankingRuleGraph, + ConditionDocIdsCache, DeadEndPathCache, ProximityGraph, RankingRuleGraph, RankingRuleGraphTrait, TypoGraph, }; use super::small_bitmap::SmallBitmap; @@ -85,12 +85,12 @@ pub struct GraphBasedRankingRuleState { /// The current graph graph: RankingRuleGraph, /// Cache to retrieve the docids associated with each edge - edge_conditions_cache: EdgeConditionDocIdsCache, + conditions_cache: ConditionDocIdsCache, /// Cache used to optimistically discard paths that resolve to no documents. dead_end_path_cache: DeadEndPathCache, /// A structure giving the list of possible costs from each node to the end node, /// along with a set of unavoidable edges that must be traversed to achieve that distance. - all_distances: MappedInterner)>, QueryNode>, + all_distances: MappedInterner)>, QueryNode>, /// An index in the first element of `all_distances`, giving the cost of the next bucket cur_distance_idx: usize, } @@ -101,7 +101,7 @@ pub struct GraphBasedRankingRuleState { fn remove_empty_edges<'ctx, G: RankingRuleGraphTrait>( ctx: &mut SearchContext<'ctx>, graph: &mut RankingRuleGraph, - condition_docids_cache: &mut EdgeConditionDocIdsCache, + condition_docids_cache: &mut ConditionDocIdsCache, universe: &RoaringBitmap, dead_end_path_cache: &mut DeadEndPathCache, ) -> Result<()> { @@ -135,7 +135,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase query_graph: &QueryGraph, ) -> Result<()> { let mut graph = RankingRuleGraph::build(ctx, query_graph.clone())?; - let mut condition_docids_cache = EdgeConditionDocIdsCache::default(); + let mut condition_docids_cache = ConditionDocIdsCache::default(); let mut dead_end_path_cache = DeadEndPathCache::new(&graph.conditions_interner); // First simplify the graph as much as possible, by computing the docids of all the conditions @@ -153,7 +153,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase let state = GraphBasedRankingRuleState { graph, - edge_conditions_cache: condition_docids_cache, + conditions_cache: condition_docids_cache, dead_end_path_cache, all_distances, cur_distance_idx: 0, @@ -181,7 +181,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase remove_empty_edges( ctx, &mut state.graph, - &mut state.edge_conditions_cache, + &mut state.conditions_cache, universe, &mut state.dead_end_path_cache, )?; @@ -204,7 +204,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase let GraphBasedRankingRuleState { graph, - edge_conditions_cache: condition_docids_cache, + conditions_cache: condition_docids_cache, dead_end_path_cache, all_distances, cur_distance_idx: _, @@ -326,8 +326,8 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase let mut used_phrases = HashSet::new(); for condition in used_conditions.iter() { let condition = graph.conditions_interner.get(condition); - used_words.extend(G::words_used_by_edge_condition(ctx, condition)?); - used_phrases.extend(G::phrases_used_by_edge_condition(ctx, condition)?); + used_words.extend(G::words_used_by_condition(ctx, condition)?); + used_phrases.extend(G::phrases_used_by_condition(ctx, condition)?); } // 2. Remove the unused words and phrases from all the nodes in the graph let mut nodes_to_remove = vec![]; diff --git a/milli/src/search/new/logger/detailed.rs b/milli/src/search/new/logger/detailed.rs index 96f4092b1..1ed992c56 100644 --- a/milli/src/search/new/logger/detailed.rs +++ b/milli/src/search/new/logger/detailed.rs @@ -11,7 +11,7 @@ use crate::search::new::query_graph::QueryNodeData; use crate::search::new::query_term::{LocatedQueryTerm, QueryTerm}; use crate::search::new::ranking_rule_graph::{ DeadEndPathCache, Edge, ProximityCondition, ProximityGraph, RankingRuleGraph, - RankingRuleGraphTrait, TypoEdge, TypoGraph, + RankingRuleGraphTrait, TypoCondition, TypoGraph, }; use crate::search::new::small_bitmap::SmallBitmap; use crate::search::new::{QueryGraph, QueryNode, SearchContext}; @@ -51,10 +51,10 @@ pub enum SearchEvents { }, TypoState { graph: RankingRuleGraph, - paths: Vec>>, + paths: Vec>>, dead_end_path_cache: DeadEndPathCache, universe: RoaringBitmap, - distances: MappedInterner)>, QueryNode>, + distances: MappedInterner)>, QueryNode>, cost: u16, }, RankingRuleSkipBucket { @@ -188,10 +188,10 @@ impl SearchLogger for DetailedSearchLogger { fn log_typo_state( &mut self, query_graph: &RankingRuleGraph, - paths_map: &[Vec>], + paths_map: &[Vec>], dead_end_path_cache: &DeadEndPathCache, universe: &RoaringBitmap, - distances: &MappedInterner)>, QueryNode>, + distances: &MappedInterner)>, QueryNode>, cost: u16, ) { self.events.push(SearchEvents::TypoState { @@ -430,7 +430,7 @@ results.{random} {{ ctx: &mut SearchContext, node_idx: Interned, node: &QueryNode, - distances: &[(u16, SmallBitmap)], + distances: &[(u16, SmallBitmap)], file: &mut File, ) { match &node.data { @@ -527,9 +527,9 @@ shape: class" fn ranking_rule_graph_d2_description( ctx: &mut SearchContext, graph: &RankingRuleGraph, - paths: &[Vec>], + paths: &[Vec>], dead_end_paths_cache: &DeadEndPathCache, - distances: MappedInterner)>, QueryNode>, + distances: MappedInterner)>, QueryNode>, file: &mut File, ) { writeln!(file, "direction: right").unwrap(); @@ -596,7 +596,7 @@ shape: class" fn condition_d2_description( ctx: &mut SearchContext, graph: &RankingRuleGraph, - condition_id: Interned, + condition_id: Interned, file: &mut File, ) { let condition = graph.conditions_interner.get(condition_id); @@ -606,14 +606,14 @@ shape: class" shape: class {} }}", - R::label_for_edge_condition(ctx, condition).unwrap() + R::label_for_condition(ctx, condition).unwrap() ) .unwrap(); } fn paths_d2_description( ctx: &mut SearchContext, graph: &RankingRuleGraph, - paths: &[Vec>], + paths: &[Vec>], file: &mut File, ) { for (path_idx, condition_indexes) in paths.iter().enumerate() { diff --git a/milli/src/search/new/logger/mod.rs b/milli/src/search/new/logger/mod.rs index 696f65443..ba58d049f 100644 --- a/milli/src/search/new/logger/mod.rs +++ b/milli/src/search/new/logger/mod.rs @@ -6,7 +6,8 @@ use roaring::RoaringBitmap; use super::interner::{Interned, MappedInterner}; use super::query_graph::QueryNode; use super::ranking_rule_graph::{ - DeadEndPathCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoEdge, TypoGraph, + DeadEndPathCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoCondition, + TypoGraph, }; use super::small_bitmap::SmallBitmap; use super::{RankingRule, RankingRuleQueryTrait}; @@ -76,10 +77,10 @@ pub trait SearchLogger { fn log_typo_state( &mut self, query_graph: &RankingRuleGraph, - paths: &[Vec>], + paths: &[Vec>], dead_end_path_cache: &DeadEndPathCache, universe: &RoaringBitmap, - distances: &MappedInterner)>, QueryNode>, + distances: &MappedInterner)>, QueryNode>, cost: u16, ); } @@ -147,10 +148,10 @@ impl SearchLogger for DefaultSearchLogger { fn log_typo_state( &mut self, _query_graph: &RankingRuleGraph, - _paths: &[Vec>], + _paths: &[Vec>], _dead_end_path_cache: &DeadEndPathCache, _universe: &RoaringBitmap, - _distances: &MappedInterner)>, QueryNode>, + _distances: &MappedInterner)>, QueryNode>, _cost: u16, ) { } diff --git a/milli/src/search/new/ranking_rule_graph/cheapest_paths.rs b/milli/src/search/new/ranking_rule_graph/cheapest_paths.rs index a86f1fcb0..bc0e88326 100644 --- a/milli/src/search/new/ranking_rule_graph/cheapest_paths.rs +++ b/milli/src/search/new/ranking_rule_graph/cheapest_paths.rs @@ -22,10 +22,10 @@ impl RankingRuleGraph { &mut self, from: Interned, cost: u16, - all_distances: &MappedInterner)>, QueryNode>, + all_distances: &MappedInterner)>, QueryNode>, dead_end_path_cache: &mut DeadEndPathCache, mut visit: impl FnMut( - &[Interned], + &[Interned], &mut Self, &mut DeadEndPathCache, ) -> Result>, @@ -46,16 +46,16 @@ impl RankingRuleGraph { &mut self, from: Interned, cost: u16, - all_distances: &MappedInterner)>, QueryNode>, + all_distances: &MappedInterner)>, QueryNode>, dead_end_path_cache: &mut DeadEndPathCache, visit: &mut impl FnMut( - &[Interned], + &[Interned], &mut Self, &mut DeadEndPathCache, ) -> Result>, - prev_conditions: &mut Vec>, - cur_path: &mut SmallBitmap, - forbidden_conditions: &mut SmallBitmap, + prev_conditions: &mut Vec>, + cur_path: &mut SmallBitmap, + forbidden_conditions: &mut SmallBitmap, ) -> Result { let mut any_valid = false; @@ -158,7 +158,7 @@ impl RankingRuleGraph { pub fn initialize_distances_with_necessary_edges( &self, - ) -> MappedInterner)>, QueryNode> { + ) -> MappedInterner)>, QueryNode> { let mut distances_to_end = self.query_graph.nodes.map(|_| vec![]); let mut enqueued = SmallBitmap::new(self.query_graph.nodes.len()); @@ -173,7 +173,7 @@ impl RankingRuleGraph { } while let Some(cur_node) = node_stack.pop_front() { - let mut self_distances = BTreeMap::>::new(); + let mut self_distances = BTreeMap::>::new(); let cur_node_edges = &self.edges_of_node.get(cur_node); for edge_idx in cur_node_edges.iter() { diff --git a/milli/src/search/new/ranking_rule_graph/mod.rs b/milli/src/search/new/ranking_rule_graph/mod.rs index fcb9ade3f..02a68b811 100644 --- a/milli/src/search/new/ranking_rule_graph/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/mod.rs @@ -19,11 +19,11 @@ mod typo; use std::collections::HashSet; use std::hash::Hash; -pub use condition_docids_cache::EdgeConditionDocIdsCache; +pub use condition_docids_cache::ConditionDocIdsCache; pub use dead_end_path_cache::DeadEndPathCache; pub use proximity::{ProximityCondition, ProximityGraph}; use roaring::RoaringBitmap; -pub use typo::{TypoEdge, TypoGraph}; +pub use typo::{TypoCondition, TypoGraph}; use super::interner::{DedupInterner, FixedSizeInterner, Interned, MappedInterner}; use super::logger::SearchLogger; @@ -74,48 +74,48 @@ impl PartialEq for Edge { pub trait RankingRuleGraphTrait: Sized { /// The condition of an edge connecting two query nodes. The condition /// should be sufficient to compute the edge's cost and associated document ids - /// in [`resolve_edge_condition`](RankingRuleGraphTrait::resolve_edge_condition). - type EdgeCondition: Sized + Clone + PartialEq + Eq + Hash; + /// in [`resolve_condition`](RankingRuleGraphTrait::resolve_condition). + type Condition: Sized + Clone + PartialEq + Eq + Hash; /// Return the label of the given edge condition, to be used when visualising /// the ranking rule graph. - fn label_for_edge_condition<'ctx>( + fn label_for_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result; - fn words_used_by_edge_condition<'ctx>( + fn words_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>>; - fn phrases_used_by_edge_condition<'ctx>( + + fn phrases_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>>; /// Compute the document ids associated with the given edge condition, /// restricted to the given universe. - fn resolve_edge_condition<'ctx>( + fn resolve_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge_condition: &Self::EdgeCondition, + condition: &Self::Condition, universe: &RoaringBitmap, ) -> 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`. + /// Return the costs and conditions of the edges going from the source node to the destination node fn build_edges<'ctx>( ctx: &mut SearchContext<'ctx>, - conditions_interner: &mut DedupInterner, + conditions_interner: &mut DedupInterner, source_node: &QueryNode, dest_node: &QueryNode, - ) -> Result>)>>; + ) -> Result>)>>; fn log_state( graph: &RankingRuleGraph, - paths: &[Vec>], + paths: &[Vec>], dead_end_path_cache: &DeadEndPathCache, universe: &RoaringBitmap, - distances: &MappedInterner)>, QueryNode>, + distances: &MappedInterner)>, QueryNode>, cost: u16, logger: &mut dyn SearchLogger, ); @@ -127,9 +127,9 @@ pub trait RankingRuleGraphTrait: Sized { /// but replacing the edges. pub struct RankingRuleGraph { pub query_graph: QueryGraph, - pub edges_store: FixedSizeInterner>>, - pub edges_of_node: MappedInterner>>, QueryNode>, - pub conditions_interner: FixedSizeInterner, + pub edges_store: FixedSizeInterner>>, + pub edges_of_node: MappedInterner>>, QueryNode>, + pub conditions_interner: FixedSizeInterner, } impl Clone for RankingRuleGraph { fn clone(&self) -> Self { @@ -143,7 +143,7 @@ impl Clone for RankingRuleGraph { } impl RankingRuleGraph { /// Remove all edges with the given condition - pub fn remove_edges_with_condition(&mut self, condition_to_remove: Interned) { + pub fn remove_edges_with_condition(&mut self, condition_to_remove: Interned) { for (edge_id, edge_opt) in self.edges_store.iter_mut() { let Some(edge) = edge_opt.as_mut() else { continue }; let Some(condition) = edge.condition else { continue }; diff --git a/milli/src/search/new/ranking_rule_graph/path_set.rs b/milli/src/search/new/ranking_rule_graph/path_set.rs index 19c7d012e..1a87c9604 100644 --- a/milli/src/search/new/ranking_rule_graph/path_set.rs +++ b/milli/src/search/new/ranking_rule_graph/path_set.rs @@ -4,7 +4,7 @@ use crate::search::new::interner::Interned; -/// A set of `Vec>`. +/// A set of `Vec>` implemented as a prefix tree. pub struct PathSet { nodes: Vec<(Interned, Self)>, is_end: bool, 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 cdf167cb0..bf5278f8d 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 @@ -6,7 +6,7 @@ use crate::{CboRoaringBitmapCodec, Result}; pub fn compute_docids<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &ProximityCondition, + condition: &ProximityCondition, universe: &RoaringBitmap, ) -> Result { let SearchContext { @@ -18,7 +18,7 @@ pub fn compute_docids<'ctx>( phrase_interner, term_interner, } = ctx; - let pairs = match edge { + let pairs = match condition { ProximityCondition::Term { term } => { return term_docids .get_query_term_docids( 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 d5655e949..9a6080301 100644 --- a/milli/src/search/new/ranking_rule_graph/proximity/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/proximity/mod.rs @@ -45,11 +45,11 @@ pub enum ProximityCondition { pub enum ProximityGraph {} impl RankingRuleGraphTrait for ProximityGraph { - type EdgeCondition = ProximityCondition; + type Condition = ProximityCondition; - fn resolve_edge_condition<'ctx>( + fn resolve_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - condition: &Self::EdgeCondition, + condition: &Self::Condition, universe: &RoaringBitmap, ) -> Result { compute_docids::compute_docids(ctx, condition, universe) @@ -57,10 +57,10 @@ impl RankingRuleGraphTrait for ProximityGraph { fn build_edges<'ctx>( ctx: &mut SearchContext<'ctx>, - conditions_interner: &mut DedupInterner, + conditions_interner: &mut DedupInterner, source_node: &QueryNode, dest_node: &QueryNode, - ) -> Result>)>> { + ) -> Result>)>> { build::build_edges(ctx, conditions_interner, source_node, dest_node) } @@ -76,11 +76,11 @@ impl RankingRuleGraphTrait for ProximityGraph { logger.log_proximity_state(graph, paths, dead_end_path_cache, universe, distances, cost); } - fn label_for_edge_condition<'ctx>( + fn label_for_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result { - match edge { + match condition { ProximityCondition::Term { term } => { let term = ctx.term_interner.get(*term); Ok(format!("{} : exists", ctx.word_interner.get(term.original))) @@ -117,11 +117,11 @@ impl RankingRuleGraphTrait for ProximityGraph { } } - fn words_used_by_edge_condition<'ctx>( + fn words_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>> { - match edge { + match condition { ProximityCondition::Term { term } => { let term = ctx.term_interner.get(*term); Ok(HashSet::from_iter(term.all_single_words_except_prefix_db())) @@ -153,11 +153,11 @@ impl RankingRuleGraphTrait for ProximityGraph { } } - fn phrases_used_by_edge_condition<'ctx>( + fn phrases_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>> { - match edge { + match condition { ProximityCondition::Term { term } => { let term = ctx.term_interner.get(*term); Ok(HashSet::from_iter(term.all_phrases())) 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 b41787ac2..0b81ec0ec 100644 --- a/milli/src/search/new/ranking_rule_graph/typo/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/typo/mod.rs @@ -14,19 +14,18 @@ use std::fmt::Write; use std::iter::FromIterator; #[derive(Clone, PartialEq, Eq, Hash)] -pub struct TypoEdge { +pub struct TypoCondition { term: Interned, - nbr_typos: u8, } pub enum TypoGraph {} impl RankingRuleGraphTrait for TypoGraph { - type EdgeCondition = TypoEdge; + type Condition = TypoCondition; - fn resolve_edge_condition<'db_cache, 'ctx>( + fn resolve_condition<'db_cache, 'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, universe: &RoaringBitmap, ) -> Result { let SearchContext { @@ -47,7 +46,7 @@ impl RankingRuleGraphTrait for TypoGraph { word_interner, term_interner, phrase_interner, - edge.term, + condition.term, )?; Ok(docids) @@ -55,10 +54,10 @@ impl RankingRuleGraphTrait for TypoGraph { fn build_edges<'ctx>( ctx: &mut SearchContext<'ctx>, - conditions_interner: &mut DedupInterner, + conditions_interner: &mut DedupInterner, _from_node: &QueryNode, to_node: &QueryNode, - ) -> Result>)>> { + ) -> Result>)>> { let SearchContext { term_interner, .. } = ctx; match &to_node.data { QueryNodeData::Term(LocatedQueryTerm { value, positions }) => { @@ -121,10 +120,10 @@ impl RankingRuleGraphTrait for TypoGraph { if !new_term.is_empty() { edges.push(( nbr_typos as u8 + base_cost, - Some(conditions_interner.insert(TypoEdge { - term: term_interner.insert(new_term), - nbr_typos: nbr_typos as u8, - })), + Some( + conditions_interner + .insert(TypoCondition { term: term_interner.insert(new_term) }), + ), )) } } @@ -137,21 +136,21 @@ impl RankingRuleGraphTrait for TypoGraph { fn log_state( graph: &RankingRuleGraph, - paths: &[Vec>], + paths: &[Vec>], dead_end_path_cache: &DeadEndPathCache, universe: &RoaringBitmap, - distances: &MappedInterner)>, QueryNode>, + distances: &MappedInterner)>, QueryNode>, cost: u16, logger: &mut dyn SearchLogger, ) { logger.log_typo_state(graph, paths, dead_end_path_cache, universe, distances, cost); } - fn label_for_edge_condition<'ctx>( + fn label_for_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result { - let TypoEdge { term, nbr_typos: _ } = edge; + let TypoCondition { term } = condition; let term = ctx.term_interner.get(*term); let QueryTerm { original: _, @@ -203,20 +202,20 @@ impl RankingRuleGraphTrait for TypoGraph { Ok(s) } - fn words_used_by_edge_condition<'ctx>( + fn words_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>> { - let TypoEdge { term, .. } = edge; + let TypoCondition { term, .. } = condition; let term = ctx.term_interner.get(*term); Ok(HashSet::from_iter(term.all_single_words_except_prefix_db())) } - fn phrases_used_by_edge_condition<'ctx>( + fn phrases_used_by_condition<'ctx>( ctx: &mut SearchContext<'ctx>, - edge: &Self::EdgeCondition, + condition: &Self::Condition, ) -> Result>> { - let TypoEdge { term, .. } = edge; + let TypoCondition { term, .. } = condition; let term = ctx.term_interner.get(*term); Ok(HashSet::from_iter(term.all_phrases())) }