From 0d6e8b5c31233d4548c90344f09c5b17178a5b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Thu, 30 Mar 2023 14:48:12 +0200 Subject: [PATCH] Fix phrase search bug when the phrase has only one word --- milli/src/search/new/resolve_query_graph.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/milli/src/search/new/resolve_query_graph.rs b/milli/src/search/new/resolve_query_graph.rs index 707082cab..ef7adad14 100644 --- a/milli/src/search/new/resolve_query_graph.rs +++ b/milli/src/search/new/resolve_query_graph.rs @@ -121,14 +121,27 @@ pub fn compute_phrase_docids( phrase: Interned, ) -> Result { 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));