Rewrite the CONTAINS filter with the MultiOps trait

This commit is contained in:
Kerollmops 2023-05-16 11:06:25 +02:00
parent d0ce1453a6
commit 50629cf735
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -304,18 +304,19 @@ impl<'a> Filter<'a> {
Condition::Contains(val) => { Condition::Contains(val) => {
let finder = Finder::new(val.value()); let finder = Finder::new(val.value());
let base = FacetGroupKey { field_id, level: 0, left_bound: "" }; let base = FacetGroupKey { field_id, level: 0, left_bound: "" };
// TODO use the roaring::MultiOps trait let docids = strings_db
let mut docids = RoaringBitmap::new();
for result in strings_db
.prefix_iter(rtxn, &base)? .prefix_iter(rtxn, &base)?
.remap_data_type::<LazyDecode<FacetGroupValueCodec>>() .remap_data_type::<LazyDecode<FacetGroupValueCodec>>()
{ .filter_map(|result| match result {
let (FacetGroupKey { left_bound, .. }, lazy_group_value) = result?; Ok((FacetGroupKey { left_bound, .. }, lazy_group_value)) => {
if finder.find(left_bound.as_bytes()).is_some() { match finder.find(left_bound.as_bytes()) {
let FacetGroupValue { bitmap, .. } = lazy_group_value.decode()?; Some(_) => Some(lazy_group_value.decode().map(|gv| gv.bitmap)),
docids |= bitmap; None => None,
} }
} }
Err(e) => Some(Err(e)),
})
.union()?;
return Ok(docids); return Ok(docids);
} }