mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 08:48:32 +08:00
Run cargo fmt
This commit is contained in:
parent
d10d78d520
commit
196f79115a
@ -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,12 +191,13 @@ 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)?;
|
||||||
|
|
||||||
// everything after `IN` can be a failure
|
// everything after `IN` can be a failure
|
||||||
let (input, _) = cut_with_err(tag("]"), |_| {
|
let (input, _) = cut_with_err(tag("]"), |_| {
|
||||||
if eof::<_, ()>(input).is_ok() {
|
if eof::<_, ()>(input).is_ok() {
|
||||||
@ -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))
|
||||||
@ -378,60 +378,60 @@ pub mod tests {
|
|||||||
// simple test
|
// simple test
|
||||||
(
|
(
|
||||||
"x = AND",
|
"x = AND",
|
||||||
Fc::Not(Box::new(Fc::Not(Box::new(Fc::In {
|
Fc::Not(Box::new(Fc::Not(Box::new(Fc::In {
|
||||||
fid: rtok("NOT NOT", "colour"),
|
fid: rtok("NOT NOT", "colour"),
|
||||||
els: vec![]
|
els: vec![]
|
||||||
}))))
|
}))))
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"colour IN[]",
|
"colour IN[]",
|
||||||
Fc::In {
|
Fc::In {
|
||||||
fid: rtok("", "colour"),
|
fid: rtok("", "colour"),
|
||||||
els: vec![]
|
els: vec![]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"colour IN[green]",
|
"colour IN[green]",
|
||||||
Fc::In {
|
Fc::In {
|
||||||
fid: rtok("", "colour"),
|
fid: rtok("", "colour"),
|
||||||
els: vec![rtok("colour IN[", "green")]
|
els: vec![rtok("colour IN[", "green")]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"colour IN[green,]",
|
"colour IN[green,]",
|
||||||
Fc::In {
|
Fc::In {
|
||||||
fid: rtok("", "colour"),
|
fid: rtok("", "colour"),
|
||||||
els: vec![rtok("colour IN[", "green")]
|
els: vec![rtok("colour IN[", "green")]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"colour IN[green,blue]",
|
"colour IN[green,blue]",
|
||||||
Fc::In {
|
Fc::In {
|
||||||
fid: rtok("", "colour"),
|
fid: rtok("", "colour"),
|
||||||
els: vec![
|
els: vec![
|
||||||
rtok("colour IN[", "green"),
|
rtok("colour IN[", "green"),
|
||||||
rtok("colour IN[green, ", "blue"),
|
rtok("colour IN[green, ", "blue"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"colour NOT IN[green,blue]",
|
"colour NOT IN[green,blue]",
|
||||||
Fc::Not(Box::new(Fc::In {
|
Fc::Not(Box::new(Fc::In {
|
||||||
fid: rtok("", "colour"),
|
fid: rtok("", "colour"),
|
||||||
els: vec![
|
els: vec![
|
||||||
rtok("colour NOT IN[", "green"),
|
rtok("colour NOT IN[", "green"),
|
||||||
rtok("colour NOT IN[green, ", "blue"),
|
rtok("colour NOT IN[green, ", "blue"),
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
" colour IN [ green , blue , ]",
|
" colour IN [ green , blue , ]",
|
||||||
Fc::In {
|
Fc::In {
|
||||||
fid: rtok(" ", "colour"),
|
fid: rtok(" ", "colour"),
|
||||||
els: vec![
|
els: vec![
|
||||||
rtok("colour IN [ ", "green"),
|
rtok("colour IN [ ", "green"),
|
||||||
rtok("colour IN [ green , ", "blue"),
|
rtok("colour IN [ green , ", "blue"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user