Skip to content

Commit 94759c3

Browse files
authored
Wrong range result when datetime was inferred in json type (#6048)
* Add test showing the problem * Add datetime filter to range query
1 parent e931711 commit 94759c3

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

quickwit/quickwit-query/src/query_ast/range_query.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ impl BuildTantivyAst for RangeQuery {
216216
} else if let Some(range) = bounds_range_f64 {
217217
sub_queries.push(query_from_fast_val_range(&empty_term, range).into());
218218
}
219-
219+
let bounds_range_date: Option<(Bound<DateTime>, Bound<DateTime>)> =
220+
convert_bound(&self.lower_bound).zip(convert_bound(&self.upper_bound));
221+
if let Some(range) = bounds_range_date {
222+
sub_queries.push(query_from_fast_val_range(&empty_term, range).into());
223+
}
220224
let mut normalizer =
221225
options
222226
.get_fast_field_tokenizer_name()
@@ -404,6 +408,34 @@ mod tests {
404408
);
405409
}
406410

411+
#[test]
412+
fn test_range_dynamic_datetime() {
413+
let range_query = RangeQuery {
414+
field: "hello".to_string(),
415+
lower_bound: Bound::Included(JsonLiteral::String(
416+
"2020-12-09T16:09:53+00:00".to_string(),
417+
)),
418+
upper_bound: Bound::Included(JsonLiteral::String(
419+
"2020-12-09T16:09:53+00:00".to_string(),
420+
)),
421+
};
422+
let schema = make_schema(true);
423+
let tantivy_ast = range_query
424+
.build_tantivy_ast_call(&BuildTantivyAstContext::for_test(&schema))
425+
.unwrap();
426+
assert_eq!(
427+
format!("{tantivy_ast:?}"),
428+
"Bool(TantivyBoolQuery { must: [], must_not: [], should: [Leaf(FastFieldRangeQuery { \
429+
bounds: BoundsRange { lower_bound: Included(Term(field=6, type=Json, path=hello, \
430+
type=Date, 2020-12-09T16:09:53Z)), upper_bound: Included(Term(field=6, type=Json, \
431+
path=hello, type=Date, 2020-12-09T16:09:53Z)) } }), Leaf(FastFieldRangeQuery { \
432+
bounds: BoundsRange { lower_bound: Included(Term(field=6, type=Json, path=hello, \
433+
type=Str, \"2020-12-09T16:09:53+00:00\")), upper_bound: Included(Term(field=6, \
434+
type=Json, path=hello, type=Str, \"2020-12-09T16:09:53+00:00\")) } })], filter: [], \
435+
minimum_should_match: None })"
436+
);
437+
}
438+
407439
#[test]
408440
fn test_range_query_not_fast_field() {
409441
let range_query = RangeQuery {

quickwit/rest-api-tests/scenarii/qw_search_api/0001_ts_range.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ params:
3434
query: "ts:>=1684993002 AND ts:<1684993004"
3535
expected:
3636
num_hits: 2
37+
---
38+
endpoint: simple/search
39+
params:
40+
query: "auto_date:>=2023-05-25T00:00:00Z AND auto_date:<2023-05-26T00:00:00Z"
41+
expected:
42+
num_hits: 2

quickwit/rest-api-tests/scenarii/qw_search_api/_setup.quickwit.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ endpoint: simple/ingest
3030
params:
3131
commit: force
3232
ndjson:
33-
- {"ts": 1684993001, "not_fast": 1684993001}
34-
- {"ts": 1684993002, "not_fast": 1684993002}
33+
- {"ts": 1684993001, "not_fast": 1684993001, "auto_date": "2023-05-25T10:00:00Z"}
34+
- {"ts": 1684993002, "not_fast": 1684993002, "auto_date": "2023-05-25T11:00:00Z"}
3535
---
3636
# Ingest documents split #2
3737
method: POST

0 commit comments

Comments
 (0)