Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion quickwit/quickwit-query/src/query_ast/full_text_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl FullTextQuery {

#[cfg(test)]
mod tests {
use tantivy::schema::{Schema, TEXT};
use tantivy::schema::{DateOptions, DateTimePrecision, Schema, TEXT};

use crate::BooleanOperand;
use crate::query_ast::tantivy_query_ast::TantivyQueryAst;
Expand Down Expand Up @@ -379,6 +379,59 @@ mod tests {
);
}

#[test]
fn test_full_text_datetime() {
let full_text_query = FullTextQuery {
field: "ts".to_string(),
text: "2025-12-13T16:13:12.666777Z".to_string(),
params: super::FullTextParams {
tokenizer: Some("raw".to_string()),
mode: FullTextMode::Phrase { slop: 1 },
zero_terms_query: crate::MatchAllOrNone::MatchAll,
},
lenient: false,
};
{
// indexed, we truncate to the second
let mut schema_builder = Schema::builder();
schema_builder.add_date_field(
"ts",
DateOptions::default()
.set_precision(DateTimePrecision::Milliseconds)
.set_fast()
.set_indexed(),
);
let schema = schema_builder.build();
let ast: TantivyQueryAst = full_text_query
.build_tantivy_ast_call(&BuildTantivyAstContext::for_test(&schema))
.unwrap();
let leaf = ast.as_leaf().unwrap();
assert_eq!(
&format!("{leaf:?}"),
r#"TermQuery(Term(field=0, type=Date, 2025-12-13T16:13:12Z))"#
);
}
{
// not indexed, we truncate to fastfield precision
let mut schema_builder = Schema::builder();
schema_builder.add_date_field(
"ts",
DateOptions::default()
.set_precision(DateTimePrecision::Milliseconds)
.set_fast(),
);
let schema = schema_builder.build();
let ast: TantivyQueryAst = full_text_query
.build_tantivy_ast_call(&BuildTantivyAstContext::for_test(&schema))
.unwrap();
let leaf = ast.as_leaf().unwrap();
assert_eq!(
&format!("{leaf:?}"),
r#"TermQuery(Term(field=0, type=Date, 2025-12-13T16:13:12.666Z))"#
);
}
}

#[test]
fn test_full_text_bool_mode() {
let full_text_query = FullTextQuery {
Expand Down
8 changes: 6 additions & 2 deletions quickwit/quickwit-query/src/query_ast/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ fn compute_query_with_field(
let term = Term::from_field_bool(field, bool_val);
Ok(make_term_query(term))
}
FieldType::Date(_) => {
FieldType::Date(date_options) => {
let dt = parse_value_from_user_text(value, field_entry.name())?;
let term = Term::from_field_date_for_search(field, dt);
let term = if date_options.is_indexed() {
Term::from_field_date_for_search(field, dt)
} else {
Term::from_field_date(field, dt.truncate(date_options.get_precision()))
};
Ok(make_term_query(term))
}
FieldType::Str(text_options) => {
Expand Down