Simplify implementation of equality condition in filters

This commit is contained in:
Loïc Lecrenier 2022-12-07 12:19:32 +01:00
parent 1c9555566e
commit 4ac8f96342

View File

@ -4,7 +4,6 @@ use std::ops::Bound::{self, Excluded, Included};
use either::Either; use either::Either;
pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Token}; pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Token};
use heed::types::DecodeIgnore;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use super::facet_range_search; use super::facet_range_search;
@ -200,20 +199,10 @@ impl<'a> Filter<'a> {
.unwrap_or_default(); .unwrap_or_default();
let number = val.parse_finite_float().ok(); let number = val.parse_finite_float().ok();
let number_docids = match number { let number_docids = match number {
Some(n) => { Some(n) => numbers_db
let n = Included(n); .get(rtxn, &FacetGroupKey { field_id, level: 0, left_bound: n })?
let mut output = RoaringBitmap::new(); .map(|v| v.bitmap)
Self::explore_facet_number_levels( .unwrap_or_default(),
rtxn,
numbers_db,
field_id,
0,
n,
n,
&mut output,
)?;
output
}
None => RoaringBitmap::new(), None => RoaringBitmap::new(),
}; };
return Ok(string_docids | number_docids); return Ok(string_docids | number_docids);
@ -226,41 +215,10 @@ impl<'a> Filter<'a> {
} }
}; };
// Ask for the biggest value that can exist for this specific field, if it exists
// that's fine if it don't, the value just before will be returned instead.
let biggest_level = numbers_db
.remap_data_type::<DecodeIgnore>()
.get_lower_than_or_equal_to(
rtxn,
&FacetGroupKey { field_id, level: u8::MAX, left_bound: f64::MAX },
)?
.and_then(
|(FacetGroupKey { field_id: id, level, .. }, _)| {
if id == field_id {
Some(level)
} else {
None
}
},
);
match biggest_level {
Some(level) => {
let mut output = RoaringBitmap::new(); let mut output = RoaringBitmap::new();
Self::explore_facet_number_levels( Self::explore_facet_number_levels(rtxn, numbers_db, field_id, left, right, &mut output)?;
rtxn,
numbers_db,
field_id,
level,
left,
right,
&mut output,
)?;
Ok(output) Ok(output)
} }
None => Ok(RoaringBitmap::new()),
}
}
/// Aggregates the documents ids that are part of the specified range automatically /// Aggregates the documents ids that are part of the specified range automatically
/// going deeper through the levels. /// going deeper through the levels.
@ -268,18 +226,11 @@ impl<'a> Filter<'a> {
rtxn: &heed::RoTxn, rtxn: &heed::RoTxn,
db: heed::Database<FacetGroupKeyCodec<OrderedF64Codec>, FacetGroupValueCodec>, db: heed::Database<FacetGroupKeyCodec<OrderedF64Codec>, FacetGroupValueCodec>,
field_id: FieldId, field_id: FieldId,
level: u8,
left: Bound<f64>, left: Bound<f64>,
right: Bound<f64>, right: Bound<f64>,
output: &mut RoaringBitmap, output: &mut RoaringBitmap,
) -> Result<()> { ) -> Result<()> {
match (left, right) { match (left, right) {
// If the request is an exact value we must go directly to the deepest level.
(Included(l), Included(r)) if l == r && level > 0 => {
return Self::explore_facet_number_levels(
rtxn, db, field_id, 0, left, right, output,
);
}
// lower TO upper when lower > upper must return no result // lower TO upper when lower > upper must return no result
(Included(l), Included(r)) if l > r => return Ok(()), (Included(l), Included(r)) if l > r => return Ok(()),
(Included(l), Excluded(r)) if l >= r => return Ok(()), (Included(l), Excluded(r)) if l >= r => return Ok(()),