Fix phrase search bug when the phrase has only one word

This commit is contained in:
Loïc Lecrenier 2023-03-30 14:48:12 +02:00
parent d48cdc67a0
commit 0d6e8b5c31

View File

@ -121,14 +121,27 @@ pub fn compute_phrase_docids(
phrase: Interned<Phrase>,
) -> Result<RoaringBitmap> {
let Phrase { words } = ctx.phrase_interner.get(phrase).clone();
if words.is_empty() {
return Ok(RoaringBitmap::new());
}
if words.len() == 1 {
if let Some(word) = &words[0] {
if let Some(word_docids) = ctx.get_db_word_docids(*word)? {
return RoaringBitmapCodec::bytes_decode(word_docids)
.ok_or(heed::Error::Decoding.into());
} else {
return Ok(RoaringBitmap::new());
}
} else {
return Ok(RoaringBitmap::new());
}
}
let mut candidates = RoaringBitmap::new();
let mut first_iter = true;
let winsize = words.len().min(3);
if words.is_empty() {
return Ok(candidates);
}
for win in words.windows(winsize) {
// Get all the documents with the matching distance for each word pairs.
let mut bitmaps = Vec::with_capacity(winsize.pow(2));