Run cargo fmt

This commit is contained in:
Loïc Lecrenier 2022-07-18 17:09:52 +02:00
parent d10d78d520
commit 196f79115a
2 changed files with 50 additions and 42 deletions

View File

@ -164,10 +164,8 @@ fn ws<'a, O>(inner: impl FnMut(Span<'a>) -> IResult<O>) -> impl FnMut(Span<'a>)
delimited(multispace0, inner, multispace0) delimited(multispace0, inner, multispace0)
} }
/// value_list = (value ("," value)* ","?)? /// value_list = (value ("," value)* ","?)?
fn parse_value_list<'a>(input: Span<'a>) -> IResult<Vec<Token<'a>>> { fn parse_value_list<'a>(input: Span<'a>) -> IResult<Vec<Token<'a>>> {
// TODO: here, I should return a failure with a clear explanation whenever possible // TODO: here, I should return a failure with a clear explanation whenever possible
// for example: // for example:
// * expected the name of a field, but got `AND` // * expected the name of a field, but got `AND`
@ -193,9 +191,10 @@ fn parse_in(input: Span) -> IResult<FilterCondition> {
let (input, _) = ws(tag("IN"))(input)?; let (input, _) = ws(tag("IN"))(input)?;
// everything after `IN` can be a failure // everything after `IN` can be a failure
let (input, _) = cut_with_err(tag("["), |_| { let (input, _) =
Error::new_from_kind(input, ErrorKind::InOpeningBracket) cut_with_err(tag("["), |_| Error::new_from_kind(input, ErrorKind::InOpeningBracket))(
})(input)?; input,
)?;
let (input, content) = cut(parse_value_list)(input)?; let (input, content) = cut(parse_value_list)(input)?;
@ -218,18 +217,19 @@ fn parse_not_in(input: Span) -> IResult<FilterCondition> {
let (input, _) = multispace1(input)?; let (input, _) = multispace1(input)?;
let (input, _) = ws(tag("IN"))(input)?; let (input, _) = ws(tag("IN"))(input)?;
// everything after `IN` can be a failure // everything after `IN` can be a failure
let (input, _) = cut_with_err(tag("["), |_| { let (input, _) =
Error::new_from_kind(input, ErrorKind::InOpeningBracket) cut_with_err(tag("["), |_| Error::new_from_kind(input, ErrorKind::InOpeningBracket))(
})(input)?; input,
)?;
let (input, content) = cut(parse_value_list)(input)?; let (input, content) = cut(parse_value_list)(input)?;
// everything after `IN` can be a failure // everything after `IN` can be a failure
let (input, _) = cut_with_err(tag("]"), |_| { let (input, _) =
Error::new_from_kind(input, ErrorKind::InClosingBracket) cut_with_err(tag("]"), |_| Error::new_from_kind(input, ErrorKind::InClosingBracket))(
})(input)?; input,
)?;
let filter = FilterCondition::Not(Box::new(FilterCondition::In { fid: value, els: content })); let filter = FilterCondition::Not(Box::new(FilterCondition::In { fid: value, els: content }));
Ok((input, filter)) Ok((input, filter))

View File

@ -302,9 +302,7 @@ impl<'a> Filter<'a> {
} }
Condition::NotEqual(val) => { Condition::NotEqual(val) => {
let operator = Condition::Equal(val.clone()); let operator = Condition::Equal(val.clone());
let docids = Self::evaluate_operator( let docids = Self::evaluate_operator(rtxn, index, field_id, &operator)?;
rtxn, index, field_id, &operator,
)?;
let all_ids = index.documents_ids(rtxn)?; let all_ids = index.documents_ids(rtxn)?;
return Ok(all_ids - docids); return Ok(all_ids - docids);
} }
@ -421,20 +419,30 @@ impl<'a> Filter<'a> {
FilterCondition::Or(subfilters) => { FilterCondition::Or(subfilters) => {
let mut bitmap = RoaringBitmap::new(); let mut bitmap = RoaringBitmap::new();
for f in subfilters { for f in subfilters {
bitmap |= Self::inner_evaluate(&(f.clone()).into(), rtxn, index, filterable_fields)?; bitmap |=
Self::inner_evaluate(&(f.clone()).into(), rtxn, index, filterable_fields)?;
} }
Ok(bitmap) Ok(bitmap)
} }
FilterCondition::And(subfilters) => { FilterCondition::And(subfilters) => {
let mut subfilters_iter = subfilters.iter(); let mut subfilters_iter = subfilters.iter();
if let Some(first_subfilter) = subfilters_iter.next() { if let Some(first_subfilter) = subfilters_iter.next() {
let mut bitmap = let mut bitmap = Self::inner_evaluate(
Self::inner_evaluate(&(first_subfilter.clone()).into(), rtxn, index, filterable_fields)?; &(first_subfilter.clone()).into(),
rtxn,
index,
filterable_fields,
)?;
for f in subfilters_iter { for f in subfilters_iter {
if bitmap.is_empty() { if bitmap.is_empty() {
return Ok(bitmap); return Ok(bitmap);
} }
bitmap &= Self::inner_evaluate(&(f.clone()).into(), rtxn, index, filterable_fields)?; bitmap &= Self::inner_evaluate(
&(f.clone()).into(),
rtxn,
index,
filterable_fields,
)?;
} }
Ok(bitmap) Ok(bitmap)
} else { } else {