mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Add a cache to the contains_documents success function
This commit is contained in:
parent
a8cda248b4
commit
8db16ff306
@ -102,7 +102,7 @@ impl Node {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_reachable<F>(&self, mut contains_documents: F) -> bool
|
||||
fn is_reachable<F>(&self, contains_documents: &mut F) -> bool
|
||||
where F: FnMut((usize, u32), (usize, u32)) -> bool,
|
||||
{
|
||||
match self {
|
||||
@ -133,7 +133,7 @@ impl<F> BestProximity<F> {
|
||||
}
|
||||
|
||||
impl<F> Iterator for BestProximity<F>
|
||||
where F: FnMut((usize, u32), (usize, u32)) -> bool + Copy,
|
||||
where F: FnMut((usize, u32), (usize, u32)) -> bool,
|
||||
{
|
||||
type Item = (u32, Vec<Vec<u32>>);
|
||||
|
||||
@ -144,13 +144,15 @@ where F: FnMut((usize, u32), (usize, u32)) -> bool + Copy,
|
||||
return None;
|
||||
}
|
||||
|
||||
let BestProximity { positions, best_proximity, contains_documents } = self;
|
||||
|
||||
let result = astar_bag(
|
||||
&Node::Uninit, // start
|
||||
|n| n.successors(&self.positions, self.best_proximity),
|
||||
|n| n.successors(&positions, *best_proximity),
|
||||
|_| 0, // heuristic
|
||||
|n| { // success
|
||||
let c = n.is_complete(&self.positions) && n.proximity() >= self.best_proximity;
|
||||
if n.is_reachable(self.contains_documents) { Some(c) } else { None }
|
||||
let c = n.is_complete(&positions) && n.proximity() >= *best_proximity;
|
||||
if n.is_reachable(contains_documents) { Some(c) } else { None }
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -120,7 +120,9 @@ impl Index {
|
||||
|
||||
let mut documents = Vec::new();
|
||||
|
||||
let mut intersect_cache = HashMap::new();
|
||||
let contains_documents = |(lword, lpos): (usize, u32), (rword, rpos)| {
|
||||
*intersect_cache.entry(((lword, lpos), (rword, rpos))).or_insert_with(|| {
|
||||
use std::iter::once;
|
||||
|
||||
let left = (&words[lword], lpos);
|
||||
@ -146,6 +148,7 @@ impl Index {
|
||||
}
|
||||
|
||||
intersect_docids.map_or(false, |i| !i.is_empty())
|
||||
})
|
||||
};
|
||||
|
||||
for (proximity, mut positions) in BestProximity::new(positions, contains_documents) {
|
||||
|
Loading…
Reference in New Issue
Block a user