mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 17:11:15 +08:00
Fix node skipping by computing the accumulated proximity
This commit is contained in:
parent
37a48489da
commit
d02c5cb023
@ -35,6 +35,8 @@ enum Node {
|
|||||||
layer: usize,
|
layer: usize,
|
||||||
// The position where this node is located.
|
// The position where this node is located.
|
||||||
position: u32,
|
position: u32,
|
||||||
|
// The total accumulated proximity until this node, used for skipping nodes.
|
||||||
|
acc_proximity: u32,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,17 +47,19 @@ impl Node {
|
|||||||
fn successors(&self, positions: &[Vec<u32>], best_proximity: u32) -> Vec<(Node, u32)> {
|
fn successors(&self, positions: &[Vec<u32>], best_proximity: u32) -> Vec<(Node, u32)> {
|
||||||
match self {
|
match self {
|
||||||
Node::Uninit => {
|
Node::Uninit => {
|
||||||
positions[0].iter().map(|p| (Node::Init { layer: 0, position: *p }, 0)).collect()
|
positions[0].iter().map(|p| {
|
||||||
|
(Node::Init { layer: 0, position: *p, acc_proximity: 0 }, 0)
|
||||||
|
}).collect()
|
||||||
},
|
},
|
||||||
// We reached the highest layer
|
// We reached the highest layer
|
||||||
n @ Node::Init { .. } if n.is_complete(positions) => vec![],
|
n @ Node::Init { .. } if n.is_complete(positions) => vec![],
|
||||||
Node::Init { layer, position } => {
|
Node::Init { layer, position, acc_proximity } => {
|
||||||
let layer = layer + 1;
|
let layer = layer + 1;
|
||||||
positions[layer].iter().filter_map(|p| {
|
positions[layer].iter().filter_map(|p| {
|
||||||
let proximity = positions_proximity(*position, *p);
|
let proximity = positions_proximity(*position, *p);
|
||||||
let node = Node::Init { layer, position: *p };
|
let node = Node::Init { layer, position: *p, acc_proximity: acc_proximity + proximity };
|
||||||
// We do not produce the nodes we have already seen in previous iterations loops.
|
// We do not produce the nodes we have already seen in previous iterations loops.
|
||||||
if node.is_complete(positions) && proximity < best_proximity {
|
if node.is_complete(positions) && acc_proximity + proximity < best_proximity {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some((node, proximity))
|
Some((node, proximity))
|
||||||
|
@ -121,7 +121,10 @@ impl Index {
|
|||||||
|
|
||||||
for (proximity, mut positions) in BestProximity::new(positions) {
|
for (proximity, mut positions) in BestProximity::new(positions) {
|
||||||
// TODO we must ignore positions paths that gives nothing
|
// TODO we must ignore positions paths that gives nothing
|
||||||
if words.len() > 1 && proximity == 0 { continue }
|
if (proximity as usize) < words.len() - 1 {
|
||||||
|
eprintln!("Skipping too short proximities of {}.", proximity);
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
positions.sort_unstable();
|
positions.sort_unstable();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user