feat: Add support for Exists leaf in query parser

Signed-off-by: Darkheir <raphael.cohen@sekoia.io>
This commit is contained in:
Darkheir
2026-08-03 12:14:51 +02:00
committed by PSeitz
parent 3bb9a430dd
commit f981e6e1f1
2 changed files with 15 additions and 7 deletions
+11 -7
View File
@@ -16,8 +16,8 @@ use crate::index::Index;
use crate::json_utils::convert_to_fast_value_and_append_to_json_term;
use crate::query::range_query::{is_type_valid_for_fastfield_range_query, RangeQuery};
use crate::query::{
AllQuery, BooleanQuery, BoostQuery, EmptyQuery, FuzzyTermQuery, Occur, PhrasePrefixQuery,
PhraseQuery, Query, RegexQuery, TermQuery, TermSetQuery,
AllQuery, BooleanQuery, BoostQuery, EmptyQuery, ExistsQuery, FuzzyTermQuery, Occur,
PhrasePrefixQuery, PhraseQuery, Query, RegexQuery, TermQuery, TermSetQuery,
};
use crate::schema::{
Facet, FacetParseError, Field, FieldType, IndexRecordOption, IntoIpv6Addr, JsonObjectOptions,
@@ -856,11 +856,9 @@ impl QueryParser {
let logical_ast = LogicalAst::Leaf(Box::new(LogicalLiteral::Set { elements }));
(Some(logical_ast), errors)
}
UserInputLeaf::Exists { .. } => (
None,
vec![QueryParserError::UnsupportedQuery(
"Range query need to target a specific field.".to_string(),
)],
UserInputLeaf::Exists { field } => (
Some(LogicalAst::Leaf(Box::new(LogicalLiteral::Exists { field }))),
Vec::new(),
),
UserInputLeaf::Regex { field, pattern } => {
if !self.regexes_allowed {
@@ -952,6 +950,7 @@ fn convert_literal_to_query(
LogicalLiteral::Regex { pattern, field } => {
Box::new(RegexQuery::from_regex(pattern, field))
}
LogicalLiteral::Exists { field } => Box::new(ExistsQuery::new(field, true)),
}
}
@@ -2121,4 +2120,9 @@ mod test {
"Unsupported query: Regex queries are not allowed."
);
}
#[test]
pub fn test_exists() {
test_parse_query_to_logical_ast_helper("title:*", "exists:title", false);
}
}