mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Allow removing all the terms from a query if it contains a phrase
This commit is contained in:
parent
24e5f6f7a9
commit
58fe260c72
@ -322,33 +322,31 @@ impl QueryGraph {
|
|||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
let cost_of_term_idx = |term_idx: u8| {
|
let cost_of_term_idx = |term_idx: u8| {
|
||||||
if term_idx == first_term_idx {
|
let rank = 1 + last_term_idx - term_idx;
|
||||||
None
|
rank as u16
|
||||||
} else {
|
|
||||||
let rank = 1 + last_term_idx - term_idx;
|
|
||||||
Some(rank as u16)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
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() {
|
let mut at_least_one_phrase = false;
|
||||||
|
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() {
|
if ctx.term_interner.get(t.term_subset.original).zero_typo.phrase.is_some() {
|
||||||
|
at_least_one_phrase = true;
|
||||||
continue;
|
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) {
|
cost = std::cmp::max(cost, cost_of_term_idx(id));
|
||||||
cost = std::cmp::max(cost, t_cost);
|
|
||||||
} else {
|
|
||||||
continue 'outer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
nodes_to_remove
|
nodes_to_remove
|
||||||
.entry(cost)
|
.entry(cost)
|
||||||
.or_insert_with(|| SmallBitmap::for_interned_values_in(&self.nodes))
|
.or_insert_with(|| SmallBitmap::for_interned_values_in(&self.nodes))
|
||||||
.insert(node_id);
|
.insert(node_id);
|
||||||
}
|
}
|
||||||
nodes_to_remove.into_values().collect()
|
let mut res: Vec<_> = nodes_to_remove.into_values().collect();
|
||||||
|
if !at_least_one_phrase {
|
||||||
|
res.pop();
|
||||||
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user