Fix bugs in query graph's "remove word" and "cheapest paths" algos

This commit is contained in:
Loïc Lecrenier
2023-02-27 14:16:39 +01:00
parent 6806640ef0
commit 0e1fbbf7c6
4 changed files with 9 additions and 18 deletions

View File

@ -192,18 +192,14 @@ impl QueryGraph {
}
pub fn remove_words_at_position(&mut self, position: i8) {
let mut nodes_to_remove_keeping_edges = vec![];
let mut nodes_to_remove = vec![];
for (node_idx, node) in self.nodes.iter().enumerate() {
let node_idx = node_idx as u32;
let QueryNode::Term(LocatedQueryTerm { value: _, positions }) = node else { continue };
if positions.contains(&position) {
if positions.start() == &position {
nodes_to_remove_keeping_edges.push(node_idx)
} else if positions.contains(&position) {
nodes_to_remove.push(node_idx)
}
}
self.remove_nodes(&nodes_to_remove);
self.remove_nodes_keep_edges(&nodes_to_remove_keeping_edges);
self.simplify();