mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
introduce the reserved keywords in the filters
This commit is contained in:
parent
6d5762a6c8
commit
7ae2a7341c
@ -595,6 +595,18 @@ fn field_id(
|
||||
) -> StdResult<Option<FieldId>, PestError<Rule>> {
|
||||
// lexing ensures that we at least have a key
|
||||
let key = items.next().unwrap();
|
||||
if key.as_rule() == Rule::reserved {
|
||||
return Err(PestError::new_from_span(
|
||||
ErrorVariant::CustomError {
|
||||
message: format!(
|
||||
"`{}` is a reserved keyword and thus can't be used as a filter expression. Available filterable attributes are: {}",
|
||||
key.as_str(),
|
||||
filterable_fields.iter().join(", "),
|
||||
),
|
||||
},
|
||||
key.as_span(),
|
||||
));
|
||||
}
|
||||
|
||||
if !filterable_fields.contains(key.as_str()) {
|
||||
return Err(PestError::new_from_span(
|
||||
@ -671,6 +683,13 @@ mod tests {
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "NOT channel = ponce").unwrap();
|
||||
let expected = Operator(0, Operator::NotEqual(None, S("ponce")));
|
||||
assert_eq!(condition, expected);
|
||||
|
||||
let result = FilterCondition::from_str(&rtxn, &index, "_geo = France");
|
||||
assert!(result.is_err());
|
||||
let error = result.unwrap_err();
|
||||
assert!(error.to_string().contains(
|
||||
"`_geo` is a reserved keyword and thus can't be used as a filter expression."
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,4 +1,4 @@
|
||||
key = _{quoted | word}
|
||||
key = _{reserved | quoted | word }
|
||||
value = _{quoted | word }
|
||||
quoted = _{ (PUSH("'") | PUSH("\"")) ~ string ~ POP }
|
||||
string = {char*}
|
||||
@ -8,6 +8,7 @@ char = _{ !(PEEK | "\\") ~ ANY
|
||||
| "\\" ~ (PEEK | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
|
||||
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})}
|
||||
|
||||
reserved = { "_geo" | "_geoDistance" | "_geoPoint" | ("_geoPoint" ~ parameters) }
|
||||
// we deliberately choose to allow empty parameters to generate more specific error message later
|
||||
parameters = {("(" ~ (value ~ ",")* ~ value? ~ ")") | ""}
|
||||
condition = _{between | eq | greater | less | geq | leq | neq}
|
||||
|
Loading…
Reference in New Issue
Block a user