reduce match possibilities in docids fetchers

This commit is contained in:
many 2021-02-17 16:50:38 +01:00 committed by Kerollmops
parent 907482c8ac
commit 4128bdc859
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -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) => {
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())
},
(QueryKind::Exact { word, .. }, true) => {
} else if query.prefix {
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());
let current_docids = self.index.word_docids.get(self.rtxn, &word)?.unwrap_or_default();
docids.union_with(&current_docids);
}
Ok(docids)
},
(QueryKind::Exact { word, .. }, false) => {
} else {
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(&current_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 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())
},
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }, true) if self.in_prefix_cache(&right) => {
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::Exact { word: right, .. }, true) => {
} 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) => {
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }) => {
let l_words = word_typos(&left, false, *typo, &self.words_fst)?;
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(&current_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)
},
(QueryKind::Tolerant { typo, word: left }, QueryKind::Exact { word: right, .. }, false) => {
let l_words = word_typos(&left, false, *typo, &self.words_fst)?;
} else {
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(&current_docids);
}
}
Ok(docids)