Skip to content

Commit

Permalink
fix: phrase query may return incorrect results if there's unknown word (
Browse files Browse the repository at this point in the history
  • Loading branch information
BubbleCal authored Sep 10, 2024
1 parent 67c984f commit 8c8fb3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions rust/lance-index/src/scalar/inverted/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ mod tests {
.await
.unwrap();
assert_eq!(row_ids.len(), Some(0));

let row_ids = invert_index
.search(&SargableQuery::FullTextSearch(
FullTextSearchQuery::new("\"lance unknown\"".to_owned()).limit(Some(10)),
))
.await
.unwrap();
assert_eq!(row_ids.len(), Some(0));
}

#[tokio::test]
Expand Down
7 changes: 6 additions & 1 deletion rust/lance-index/src/scalar/inverted/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ impl InvertedIndex {
let token_ids = if !is_phrase_query(&query.query) {
token_ids.sorted_unstable().dedup().collect()
} else {
token_ids.collect()
let token_ids = token_ids.collect::<Vec<_>>();
// for phrase query, all tokens must be present
if token_ids.len() != tokens.len() {
return Ok(Vec::new());
}
token_ids
};
self.bm25_search(token_ids, query, prefilter).await
}
Expand Down

0 comments on commit 8c8fb3c

Please sign in to comment.