Don't remove phrases from the query with term matching strategy Last

This commit is contained in:
Loïc Lecrenier 2023-03-30 14:54:08 +02:00
parent 061b1e6d7c
commit 12b26cd54e
4 changed files with 11 additions and 5 deletions

View File

@ -110,7 +110,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
match terms_matching_strategy { match terms_matching_strategy {
TermsMatchingStrategy::Last => { TermsMatchingStrategy::Last => {
let removal_order = let removal_order =
query_graph.removal_order_for_terms_matching_strategy_last(); query_graph.removal_order_for_terms_matching_strategy_last(ctx);
let mut forbidden_nodes = let mut forbidden_nodes =
SmallBitmap::for_interned_values_in(&query_graph.nodes); SmallBitmap::for_interned_values_in(&query_graph.nodes);
let mut costs = query_graph.nodes.map(|_| None); let mut costs = query_graph.nodes.map(|_| None);

View File

@ -78,7 +78,7 @@ fn resolve_maximally_reduced_query_graph(
let nodes_to_remove = match matching_strategy { let nodes_to_remove = match matching_strategy {
TermsMatchingStrategy::Last => query_graph TermsMatchingStrategy::Last => query_graph
.removal_order_for_terms_matching_strategy_last() .removal_order_for_terms_matching_strategy_last(ctx)
.iter() .iter()
.flat_map(|x| x.iter()) .flat_map(|x| x.iter())
.collect(), .collect(),

View File

@ -296,7 +296,10 @@ impl QueryGraph {
} }
} }
pub fn removal_order_for_terms_matching_strategy_last(&self) -> Vec<SmallBitmap<QueryNode>> { pub fn removal_order_for_terms_matching_strategy_last(
&self,
ctx: &SearchContext,
) -> Vec<SmallBitmap<QueryNode>> {
let (first_term_idx, last_term_idx) = { let (first_term_idx, last_term_idx) = {
let mut first_term_idx = u8::MAX; let mut first_term_idx = u8::MAX;
let mut last_term_idx = 0u8; let mut last_term_idx = 0u8;
@ -329,6 +332,9 @@ impl QueryGraph {
let mut nodes_to_remove = BTreeMap::<u16, SmallBitmap<QueryNode>>::new(); let mut nodes_to_remove = BTreeMap::<u16, SmallBitmap<QueryNode>>::new();
'outer: for (node_id, node) in self.nodes.iter() { 'outer: for (node_id, node) in self.nodes.iter() {
let QueryNodeData::Term(t) = &node.data else { continue }; let QueryNodeData::Term(t) = &node.data else { continue };
if ctx.term_interner.get(t.term_subset.original).zero_typo.phrase.is_some() {
continue;
}
let mut cost = 0; let mut cost = 0;
for id in t.term_ids.clone() { for id in t.term_ids.clone() {
if let Some(t_cost) = cost_of_term_idx(id) { if let Some(t_cost) = cost_of_term_idx(id) {

View File

@ -31,7 +31,7 @@ impl<'ctx> RankingRule<'ctx, QueryGraph> for Words {
} }
fn start_iteration( fn start_iteration(
&mut self, &mut self,
_ctx: &mut SearchContext<'ctx>, ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<QueryGraph>, _logger: &mut dyn SearchLogger<QueryGraph>,
_parent_candidates: &RoaringBitmap, _parent_candidates: &RoaringBitmap,
parent_query_graph: &QueryGraph, parent_query_graph: &QueryGraph,
@ -40,7 +40,7 @@ impl<'ctx> RankingRule<'ctx, QueryGraph> for Words {
self.query_graph = Some(parent_query_graph.clone()); self.query_graph = Some(parent_query_graph.clone());
self.nodes_to_remove = match self.terms_matching_strategy { self.nodes_to_remove = match self.terms_matching_strategy {
TermsMatchingStrategy::Last => { TermsMatchingStrategy::Last => {
let mut ns = parent_query_graph.removal_order_for_terms_matching_strategy_last(); let mut ns = parent_query_graph.removal_order_for_terms_matching_strategy_last(ctx);
ns.reverse(); ns.reverse();
ns ns
} }