mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-09 13:04:30 +01:00
Change the IS NULL filter syntax to use the IS keyword
This commit is contained in:
parent
c25779afba
commit
030263caa3
@ -45,18 +45,19 @@ pub fn parse_condition(input: Span) -> IResult<FilterCondition> {
|
|||||||
Ok((input, condition))
|
Ok((input, condition))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// null = value "NULL"
|
/// null = value "IS" WS+ "NULL"
|
||||||
pub fn parse_null(input: Span) -> IResult<FilterCondition> {
|
pub fn parse_is_null(input: Span) -> IResult<FilterCondition> {
|
||||||
let (input, key) = terminated(parse_value, tag("NULL"))(input)?;
|
let (input, key) = parse_value(input)?;
|
||||||
|
|
||||||
|
let (input, _) = tuple((tag("IS"), multispace1, tag("NULL")))(input)?;
|
||||||
Ok((input, FilterCondition::Condition { fid: key, op: Null }))
|
Ok((input, FilterCondition::Condition { fid: key, op: Null }))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// null = value "NOT" WS+ "NULL"
|
/// null = value "IS" WS+ "NOT" WS+ "NULL"
|
||||||
pub fn parse_not_null(input: Span) -> IResult<FilterCondition> {
|
pub fn parse_is_not_null(input: Span) -> IResult<FilterCondition> {
|
||||||
let (input, key) = parse_value(input)?;
|
let (input, key) = parse_value(input)?;
|
||||||
|
|
||||||
let (input, _) = tuple((tag("NOT"), multispace1, tag("NULL")))(input)?;
|
let (input, _) = tuple((tag("IS"), multispace1, tag("NOT"), multispace1, tag("NULL")))(input)?;
|
||||||
Ok((input, FilterCondition::Not(Box::new(FilterCondition::Condition { fid: key, op: Null }))))
|
Ok((input, FilterCondition::Not(Box::new(FilterCondition::Condition { fid: key, op: Null }))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ mod value;
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub use condition::{parse_condition, parse_to, Condition};
|
pub use condition::{parse_condition, parse_to, Condition};
|
||||||
use condition::{parse_exists, parse_not_exists, parse_not_null, parse_null};
|
use condition::{parse_exists, parse_is_not_null, parse_is_null, parse_not_exists};
|
||||||
use error::{cut_with_err, ExpectedValueKind, NomErrorExt};
|
use error::{cut_with_err, ExpectedValueKind, NomErrorExt};
|
||||||
pub use error::{Error, ErrorKind};
|
pub use error::{Error, ErrorKind};
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
@ -414,8 +414,8 @@ fn parse_primary(input: Span, depth: usize) -> IResult<FilterCondition> {
|
|||||||
parse_in,
|
parse_in,
|
||||||
parse_not_in,
|
parse_not_in,
|
||||||
parse_condition,
|
parse_condition,
|
||||||
parse_null,
|
parse_is_null,
|
||||||
parse_not_null,
|
parse_is_not_null,
|
||||||
parse_exists,
|
parse_exists,
|
||||||
parse_not_exists,
|
parse_not_exists,
|
||||||
parse_to,
|
parse_to,
|
||||||
@ -811,7 +811,7 @@ impl<'a> std::fmt::Display for Condition<'a> {
|
|||||||
Condition::GreaterThanOrEqual(token) => write!(f, ">= {token}"),
|
Condition::GreaterThanOrEqual(token) => write!(f, ">= {token}"),
|
||||||
Condition::Equal(token) => write!(f, "= {token}"),
|
Condition::Equal(token) => write!(f, "= {token}"),
|
||||||
Condition::NotEqual(token) => write!(f, "!= {token}"),
|
Condition::NotEqual(token) => write!(f, "!= {token}"),
|
||||||
Condition::Null => write!(f, "NULL"),
|
Condition::Null => write!(f, "IS NULL"),
|
||||||
Condition::Exists => write!(f, "EXISTS"),
|
Condition::Exists => write!(f, "EXISTS"),
|
||||||
Condition::LowerThan(token) => write!(f, "< {token}"),
|
Condition::LowerThan(token) => write!(f, "< {token}"),
|
||||||
Condition::LowerThanOrEqual(token) => write!(f, "<= {token}"),
|
Condition::LowerThanOrEqual(token) => write!(f, "<= {token}"),
|
||||||
|
@ -180,7 +180,16 @@ fn is_syntax_component(c: char) -> bool {
|
|||||||
fn is_keyword(s: &str) -> bool {
|
fn is_keyword(s: &str) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
s,
|
s,
|
||||||
"AND" | "OR" | "IN" | "NOT" | "TO" | "EXISTS" | "NULL" | "_geoRadius" | "_geoBoundingBox"
|
"AND"
|
||||||
|
| "OR"
|
||||||
|
| "IN"
|
||||||
|
| "NOT"
|
||||||
|
| "TO"
|
||||||
|
| "EXISTS"
|
||||||
|
| "IS"
|
||||||
|
| "NULL"
|
||||||
|
| "_geoRadius"
|
||||||
|
| "_geoBoundingBox"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user