Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
resolve phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
irevoire committed Aug 19, 2022
1 parent 43c5894 commit 7e20d5c
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions milli/src/search/criteria/mod.rs
Original file line number Diff line number Diff line change
@@ -307,14 +307,7 @@ pub fn resolve_query_tree(
use Operation::{And, Or, Phrase, Query};

match query_tree {
And(ops) => {
let candidates = ops
.iter()
.map(|op| resolve_operation(ctx, op, wdcache))
.collect::<Result<Vec<_>>>()?;

Ok(candidates.and())
}
And(ops) => ops.into_iter().map(|op| resolve_operation(ctx, op, wdcache)).and(),
Or(_, ops) => ops.into_iter().map(|op| resolve_operation(ctx, op, wdcache)).or(),
Phrase(words) => resolve_phrase(ctx, &words),
Query(q) => Ok(query_docids(ctx, q, wdcache)?),
@@ -326,7 +319,6 @@ pub fn resolve_query_tree(

pub fn resolve_phrase(ctx: &dyn Context, phrase: &[String]) -> Result<RoaringBitmap> {
let mut candidates = RoaringBitmap::new();
let mut first_iter = true;
let winsize = phrase.len().min(7);

for win in phrase.windows(winsize) {
@@ -345,18 +337,11 @@ pub fn resolve_phrase(ctx: &dyn Context, phrase: &[String]) -> Result<RoaringBit

// We sort the bitmaps so that we perform the small intersections first, which is faster.
bitmaps.sort_unstable_by(|a, b| a.len().cmp(&b.len()));
candidates &= bitmaps.and();

for bitmap in bitmaps {
if first_iter {
candidates = bitmap;
first_iter = false;
} else {
candidates &= bitmap;
}
// There will be no match, return early
if candidates.is_empty() {
break;
}
// There will be no match, return early
if candidates.is_empty() {
break;
}
}
Ok(candidates)

0 comments on commit 7e20d5c

Please sign in to comment.