mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-12 06:24:29 +01:00
Depth-first search cache the docids unions
This commit is contained in:
parent
a3821a0b33
commit
6ddb3e722c
@ -1,4 +1,5 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
|
|
||||||
use fst::{IntoStreamer, Streamer};
|
use fst::{IntoStreamer, Streamer};
|
||||||
use levenshtein_automata::DFA;
|
use levenshtein_automata::DFA;
|
||||||
@ -215,13 +216,16 @@ impl<'a> Search<'a> {
|
|||||||
words: &[(HashMap<String, (u8, RoaringBitmap)>, RoaringBitmap)],
|
words: &[(HashMap<String, (u8, RoaringBitmap)>, RoaringBitmap)],
|
||||||
candidates: &RoaringBitmap,
|
candidates: &RoaringBitmap,
|
||||||
parent_docids: Option<&RoaringBitmap>,
|
parent_docids: Option<&RoaringBitmap>,
|
||||||
|
union_cache: &mut HashMap<(usize, u8), RoaringBitmap>,
|
||||||
) -> anyhow::Result<Option<RoaringBitmap>>
|
) -> anyhow::Result<Option<RoaringBitmap>>
|
||||||
{
|
{
|
||||||
let (words1, words2) = (&words[0].0, &words[1].0);
|
let (words1, words2) = (&words[0].0, &words[1].0);
|
||||||
let pairs = words_pair_combinations(words1, words2);
|
let pairs = words_pair_combinations(words1, words2);
|
||||||
|
|
||||||
for proximity in 1..=8 {
|
for proximity in 1..=8 {
|
||||||
|
let mut docids = match union_cache.entry((words.len(), proximity)) {
|
||||||
|
Occupied(entry) => entry.get().clone(),
|
||||||
|
Vacant(entry) => {
|
||||||
let mut docids = RoaringBitmap::new();
|
let mut docids = RoaringBitmap::new();
|
||||||
if proximity == 8 {
|
if proximity == 8 {
|
||||||
docids = candidates.clone();
|
docids = candidates.clone();
|
||||||
@ -232,6 +236,9 @@ impl<'a> Search<'a> {
|
|||||||
docids.union_with(&di);
|
docids.union_with(&di);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
entry.insert(docids).clone()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(parent_docids) = &parent_docids {
|
if let Some(parent_docids) = &parent_docids {
|
||||||
@ -242,7 +249,7 @@ impl<'a> Search<'a> {
|
|||||||
let words = &words[1..];
|
let words = &words[1..];
|
||||||
// We are the last word.
|
// We are the last word.
|
||||||
if words.len() < 2 { return Ok(Some(docids)) }
|
if words.len() < 2 { return Ok(Some(docids)) }
|
||||||
if let Some(di) = depth_first_search(index, rtxn, words, candidates, Some(&docids))? {
|
if let Some(di) = depth_first_search(index, rtxn, words, candidates, Some(&docids), union_cache)? {
|
||||||
return Ok(Some(di))
|
return Ok(Some(di))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,8 +258,10 @@ impl<'a> Search<'a> {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut union_cache = HashMap::new();
|
||||||
|
let answer = depth_first_search(index, rtxn, &derived_words, &candidates, None, &mut union_cache)?;
|
||||||
|
|
||||||
let mut documents = Vec::new();
|
let mut documents = Vec::new();
|
||||||
let answer = depth_first_search(index, rtxn, &derived_words, &candidates, None)?;
|
|
||||||
if let Some(answer) = answer {
|
if let Some(answer) = answer {
|
||||||
documents.push(answer);
|
documents.push(answer);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user