mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
reduce match possibilities in docids fetchers
This commit is contained in:
parent
907482c8ac
commit
4128bdc859
@ -49,26 +49,28 @@ pub struct HeedContext<'t> {
|
||||
|
||||
impl<'a> Context for HeedContext<'a> {
|
||||
fn query_docids(&self, query: &Query) -> anyhow::Result<RoaringBitmap> {
|
||||
match (&query.kind, query.prefix) {
|
||||
(QueryKind::Exact { word, .. }, true) if self.in_prefix_cache(&word) => {
|
||||
Ok(self.index.word_prefix_docids.get(self.rtxn, &word)?.unwrap_or_default())
|
||||
},
|
||||
(QueryKind::Exact { word, .. }, true) => {
|
||||
let words = word_typos(&word, true, 0, &self.words_fst)?;
|
||||
let mut docids = RoaringBitmap::new();
|
||||
for (word, _typo) in words {
|
||||
docids.union_with(&self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default());
|
||||
match &query.kind {
|
||||
QueryKind::Exact { word, .. } => {
|
||||
if query.prefix && self.in_prefix_cache(&word) {
|
||||
Ok(self.index.word_prefix_docids.get(self.rtxn, &word)?.unwrap_or_default())
|
||||
} else if query.prefix {
|
||||
let words = word_typos(&word, true, 0, &self.words_fst)?;
|
||||
let mut docids = RoaringBitmap::new();
|
||||
for (word, _typo) in words {
|
||||
let current_docids = self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default();
|
||||
docids.union_with(¤t_docids);
|
||||
}
|
||||
Ok(docids)
|
||||
} else {
|
||||
Ok(self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default())
|
||||
}
|
||||
Ok(docids)
|
||||
},
|
||||
(QueryKind::Exact { word, .. }, false) => {
|
||||
Ok(self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default())
|
||||
},
|
||||
(QueryKind::Tolerant { typo, word }, prefix) => {
|
||||
let words = word_typos(&word, prefix, *typo, &self.words_fst)?;
|
||||
QueryKind::Tolerant { typo, word } => {
|
||||
let words = word_typos(&word, query.prefix, *typo, &self.words_fst)?;
|
||||
let mut docids = RoaringBitmap::new();
|
||||
for (word, _typo) in words {
|
||||
docids.union_with(&self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default());
|
||||
let current_docids = self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default();
|
||||
docids.union_with(¤t_docids);
|
||||
}
|
||||
Ok(docids)
|
||||
},
|
||||
@ -76,41 +78,47 @@ impl<'a> Context for HeedContext<'a> {
|
||||
}
|
||||
|
||||
fn query_pair_proximity_docids(&self, left: &Query, right: &Query, distance: u8) -> anyhow::Result<RoaringBitmap> {
|
||||
match (&left.kind, &right.kind, right.prefix) {
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Exact { word: right, .. }, true) if self.in_prefix_cache(&right) => {
|
||||
let key = (left.as_str(), right.as_str(), distance);
|
||||
Ok(self.index.word_prefix_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default())
|
||||
let prefix = right.prefix;
|
||||
|
||||
match (&left.kind, &right.kind) {
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Exact { word: right, .. }) => {
|
||||
if prefix && self.in_prefix_cache(&right) {
|
||||
let key = (left.as_str(), right.as_str(), distance);
|
||||
Ok(self.index.word_prefix_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default())
|
||||
} else if prefix {
|
||||
let r_words = word_typos(&right, true, 0, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&[(left, 0)], &r_words, distance)
|
||||
} else {
|
||||
let key = (left.as_str(), right.as_str(), distance);
|
||||
Ok(self.index.word_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default())
|
||||
}
|
||||
},
|
||||
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }, true) if self.in_prefix_cache(&right) => {
|
||||
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }) => {
|
||||
let l_words = word_typos(&left, false, *typo, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&l_words, &[(right, 0)], distance)
|
||||
if prefix && self.in_prefix_cache(&right) {
|
||||
let mut docids = RoaringBitmap::new();
|
||||
for (left, _) in l_words {
|
||||
let key = (left.as_ref(), right.as_ref(), distance);
|
||||
let current_docids = self.index.word_prefix_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default();
|
||||
docids.union_with(¤t_docids);
|
||||
}
|
||||
Ok(docids)
|
||||
} else if prefix {
|
||||
let r_words = word_typos(&right, true, 0, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&l_words, &r_words, distance)
|
||||
} else {
|
||||
self.all_word_pair_proximity_docids(&l_words, &[(right, 0)], distance)
|
||||
}
|
||||
},
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Exact { word: right, .. }, true) => {
|
||||
let r_words = word_typos(&right, true, 0, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&[(left, 0)], &r_words, distance)
|
||||
},
|
||||
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }, true) => {
|
||||
let l_words = word_typos(&left, false, *typo, &self.words_fst)?;
|
||||
let r_words = word_typos(&right, true, 0, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&l_words, &r_words, distance)
|
||||
},
|
||||
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }, false) => {
|
||||
let l_words = word_typos(&left, false, *typo, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&l_words, &[(right, 0)], distance)
|
||||
},
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Tolerant { typo, word: right }, prefix) => {
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Tolerant { typo, word: right }) => {
|
||||
let r_words = word_typos(&right, prefix, *typo, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&[(left, 0)], &r_words, distance)
|
||||
},
|
||||
(QueryKind::Tolerant { typo: l_typo, word: left }, QueryKind::Tolerant { typo: r_typo, word: right }, prefix) => {
|
||||
(QueryKind::Tolerant { typo: l_typo, word: left }, QueryKind::Tolerant { typo: r_typo, word: right }) => {
|
||||
let l_words = word_typos(&left, false, *l_typo, &self.words_fst)?;
|
||||
let r_words = word_typos(&right, prefix, *r_typo, &self.words_fst)?;
|
||||
self.all_word_pair_proximity_docids(&l_words, &r_words, distance)
|
||||
},
|
||||
(QueryKind::Exact { word: left, .. }, QueryKind::Exact { word: right, .. }, false) => {
|
||||
let key = (left.as_str(), right.as_str(), distance);
|
||||
Ok(self.index.word_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +149,8 @@ impl<'t> HeedContext<'t> {
|
||||
for (left, _l_typo) in left_words {
|
||||
for (right, _r_typo) in right_words {
|
||||
let key = (left.as_ref(), right.as_ref(), distance);
|
||||
docids.union_with(&self.index.word_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default());
|
||||
let current_docids = self.index.word_pair_proximity_docids.get(self.rtxn, &key)?.unwrap_or_default();
|
||||
docids.union_with(¤t_docids);
|
||||
}
|
||||
}
|
||||
Ok(docids)
|
||||
|
Loading…
Reference in New Issue
Block a user