mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
Introduce the depth_first_search path resolution function
This commit is contained in:
parent
51c237f9d8
commit
a3821a0b33
@ -186,8 +186,6 @@ impl<'a> Search<'a> {
|
|||||||
|
|
||||||
debug!("candidates: {:?}", candidates);
|
debug!("candidates: {:?}", candidates);
|
||||||
|
|
||||||
let mut documents = Vec::new();
|
|
||||||
|
|
||||||
// If there is only one query word, no need to compute the best proximities.
|
// If there is only one query word, no need to compute the best proximities.
|
||||||
if derived_words.len() == 1 || candidates.is_empty() {
|
if derived_words.len() == 1 || candidates.is_empty() {
|
||||||
let found_words = derived_words.into_iter().flat_map(|(w, _)| w).map(|(w, _)| w).collect();
|
let found_words = derived_words.into_iter().flat_map(|(w, _)| w).map(|(w, _)| w).collect();
|
||||||
@ -211,31 +209,53 @@ impl<'a> Search<'a> {
|
|||||||
pairs
|
pairs
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut answer = RoaringBitmap::new();
|
fn depth_first_search(
|
||||||
for (i, words) in derived_words.windows(2).enumerate() {
|
index: &Index,
|
||||||
let pairs = words_pair_combinations(&words[0].0, &words[1].0);
|
rtxn: &heed::RoTxn,
|
||||||
eprintln!("found pairs {:?}", pairs);
|
words: &[(HashMap<String, (u8, RoaringBitmap)>, RoaringBitmap)],
|
||||||
|
candidates: &RoaringBitmap,
|
||||||
|
parent_docids: Option<&RoaringBitmap>,
|
||||||
|
) -> anyhow::Result<Option<RoaringBitmap>>
|
||||||
|
{
|
||||||
|
let (words1, words2) = (&words[0].0, &words[1].0);
|
||||||
|
let pairs = words_pair_combinations(words1, words2);
|
||||||
|
|
||||||
let mut pairs_union = RoaringBitmap::new();
|
for proximity in 1..=8 {
|
||||||
'pairs: for (w1, w2) in pairs {
|
|
||||||
for prox in 1..=7 {
|
|
||||||
let key = (w1, w2, prox);
|
|
||||||
eprintln!("{:?}", key);
|
|
||||||
if let Some(docids) = index.word_pair_proximity_docids.get(rtxn, &key)? {
|
|
||||||
pairs_union.union_with(&docids);
|
|
||||||
continue 'pairs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if i == 0 {
|
let mut docids = RoaringBitmap::new();
|
||||||
answer = pairs_union;
|
if proximity == 8 {
|
||||||
|
docids = candidates.clone();
|
||||||
} else {
|
} else {
|
||||||
answer.intersect_with(&pairs_union);
|
for (w1, w2) in pairs.iter().cloned() {
|
||||||
|
let key = (w1, w2, proximity);
|
||||||
|
if let Some(di) = index.word_pair_proximity_docids.get(rtxn, &key)? {
|
||||||
|
docids.union_with(&di);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(parent_docids) = &parent_docids {
|
||||||
|
docids.intersect_with(parent_docids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !docids.is_empty() {
|
||||||
|
let words = &words[1..];
|
||||||
|
// We are the last word.
|
||||||
|
if words.len() < 2 { return Ok(Some(docids)) }
|
||||||
|
if let Some(di) = depth_first_search(index, rtxn, words, candidates, Some(&docids))? {
|
||||||
|
return Ok(Some(di))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut documents = Vec::new();
|
||||||
|
let answer = depth_first_search(index, rtxn, &derived_words, &candidates, None)?;
|
||||||
|
if let Some(answer) = answer {
|
||||||
documents.push(answer);
|
documents.push(answer);
|
||||||
|
}
|
||||||
|
|
||||||
let found_words = derived_words.into_iter().flat_map(|(w, _)| w).map(|(w, _)| w).collect();
|
let found_words = derived_words.into_iter().flat_map(|(w, _)| w).map(|(w, _)| w).collect();
|
||||||
let documents_ids = documents.into_iter().flatten().take(limit).collect();
|
let documents_ids = documents.into_iter().flatten().take(limit).collect();
|
||||||
|
Loading…
Reference in New Issue
Block a user