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

Commit 4ac8f96

Browse files
committed
Simplify implementation of equality condition in filters
1 parent 1c95555 commit 4ac8f96

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

milli/src/search/facet/filter.rs

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ops::Bound::{self, Excluded, Included};
44

55
use either::Either;
66
pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Token};
7-
use heed::types::DecodeIgnore;
87
use roaring::RoaringBitmap;
98

109
use super::facet_range_search;
@@ -200,20 +199,10 @@ impl<'a> Filter<'a> {
200199
.unwrap_or_default();
201200
let number = val.parse_finite_float().ok();
202201
let number_docids = match number {
203-
Some(n) => {
204-
let n = Included(n);
205-
let mut output = RoaringBitmap::new();
206-
Self::explore_facet_number_levels(
207-
rtxn,
208-
numbers_db,
209-
field_id,
210-
0,
211-
n,
212-
n,
213-
&mut output,
214-
)?;
215-
output
216-
}
202+
Some(n) => numbers_db
203+
.get(rtxn, &FacetGroupKey { field_id, level: 0, left_bound: n })?
204+
.map(|v| v.bitmap)
205+
.unwrap_or_default(),
217206
None => RoaringBitmap::new(),
218207
};
219208
return Ok(string_docids | number_docids);
@@ -226,40 +215,9 @@ impl<'a> Filter<'a> {
226215
}
227216
};
228217

229-
// Ask for the biggest value that can exist for this specific field, if it exists
230-
// that's fine if it don't, the value just before will be returned instead.
231-
let biggest_level = numbers_db
232-
.remap_data_type::<DecodeIgnore>()
233-
.get_lower_than_or_equal_to(
234-
rtxn,
235-
&FacetGroupKey { field_id, level: u8::MAX, left_bound: f64::MAX },
236-
)?
237-
.and_then(
238-
|(FacetGroupKey { field_id: id, level, .. }, _)| {
239-
if id == field_id {
240-
Some(level)
241-
} else {
242-
None
243-
}
244-
},
245-
);
246-
247-
match biggest_level {
248-
Some(level) => {
249-
let mut output = RoaringBitmap::new();
250-
Self::explore_facet_number_levels(
251-
rtxn,
252-
numbers_db,
253-
field_id,
254-
level,
255-
left,
256-
right,
257-
&mut output,
258-
)?;
259-
Ok(output)
260-
}
261-
None => Ok(RoaringBitmap::new()),
262-
}
218+
let mut output = RoaringBitmap::new();
219+
Self::explore_facet_number_levels(rtxn, numbers_db, field_id, left, right, &mut output)?;
220+
Ok(output)
263221
}
264222

265223
/// Aggregates the documents ids that are part of the specified range automatically
@@ -268,18 +226,11 @@ impl<'a> Filter<'a> {
268226
rtxn: &heed::RoTxn,
269227
db: heed::Database<FacetGroupKeyCodec<OrderedF64Codec>, FacetGroupValueCodec>,
270228
field_id: FieldId,
271-
level: u8,
272229
left: Bound<f64>,
273230
right: Bound<f64>,
274231
output: &mut RoaringBitmap,
275232
) -> Result<()> {
276233
match (left, right) {
277-
// If the request is an exact value we must go directly to the deepest level.
278-
(Included(l), Included(r)) if l == r && level > 0 => {
279-
return Self::explore_facet_number_levels(
280-
rtxn, db, field_id, 0, left, right, output,
281-
);
282-
}
283234
// lower TO upper when lower > upper must return no result
284235
(Included(l), Included(r)) if l > r => return Ok(()),
285236
(Included(l), Excluded(r)) if l >= r => return Ok(()),

0 commit comments

Comments
 (0)