Skip to content

Commit 6985c52

Browse files
authored
fix: Use appropriate Term method for date search (#5857)
1 parent fb6be52 commit 6985c52

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,29 @@ mod tests {
221221
"TermQuery(Term(field=0, type=Bytes, [108, 105, 103, 104, 116, 32, 119]))"
222222
);
223223
}
224+
225+
#[test]
226+
fn test_term_query_with_date_nanosecond() {
227+
let term_query = TermQuery {
228+
field: "timestamp".to_string(),
229+
value: "2025-08-07T14:49:21.831343Z".to_string(),
230+
};
231+
let mut schema_builder = Schema::builder();
232+
schema_builder.add_date_field("timestamp", INDEXED);
233+
let schema = schema_builder.build();
234+
let tantivy_query_ast = term_query
235+
.build_tantivy_ast_call(
236+
&schema,
237+
&create_default_quickwit_tokenizer_manager(),
238+
&[],
239+
true,
240+
)
241+
.unwrap();
242+
let leaf = tantivy_query_ast.as_leaf().unwrap();
243+
// The date should have been truncated to seconds precision.
244+
assert_eq!(
245+
&format!("{leaf:?}"),
246+
"TermQuery(Term(field=0, type=Date, 2025-08-07T14:49:21Z))"
247+
);
248+
}
224249
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn compute_query_with_field(
143143
}
144144
FieldType::Date(_) => {
145145
let dt = parse_value_from_user_text(value, field_entry.name())?;
146-
let term = Term::from_field_date(field, dt);
146+
let term = Term::from_field_date_for_search(field, dt);
147147
Ok(make_term_query(term))
148148
}
149149
FieldType::Str(text_options) => {

0 commit comments

Comments
 (0)