From d0ce1453a66afb94789401b4e322b9cd910182d6 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 16 May 2023 10:58:57 +0200 Subject: [PATCH] Rewrite the STARTS WITH filter with the MultiOps trait --- milli/src/search/facet/filter.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/milli/src/search/facet/filter.rs b/milli/src/search/facet/filter.rs index 539b4e5f1..39f7c2c81 100644 --- a/milli/src/search/facet/filter.rs +++ b/milli/src/search/facet/filter.rs @@ -7,7 +7,7 @@ pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Toke use heed::types::DecodeIgnore; use heed::LazyDecode; use memchr::memmem::{Finder, FinderRev}; -use roaring::RoaringBitmap; +use roaring::{MultiOps, RoaringBitmap}; use serde_json::Value; use super::facet_range_search; @@ -320,16 +320,13 @@ impl<'a> Filter<'a> { return Ok(docids); } Condition::StartsWith(val) => { + // This can be implemented with the string level layers for a faster execution let prefix = FacetGroupKey { field_id, level: 0, left_bound: val.value() }; - // TODO use the roaring::MultiOps trait - let mut docids = RoaringBitmap::new(); - for result in - strings_db.prefix_iter(rtxn, &prefix)?.remap_key_type::() - { - let ((), group_value) = result?; - docids |= group_value.bitmap; - } - + let docids = strings_db + .prefix_iter(rtxn, &prefix)? + .remap_key_type::() + .map(|result| result.map(|(_, gv)| gv.bitmap)) + .union()?; return Ok(docids); } Condition::EndsWith(val) => {