mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-29 22:50:41 +00:00
Updated DateTime to hold timestamp in microseconds, while making date field precision configurable (#1396)
This commit is contained in:
@@ -243,13 +243,12 @@ impl MoreLikeThis {
|
||||
}
|
||||
FieldType::Date(_) => {
|
||||
for value in values {
|
||||
// TODO: Ask if this is the semantic (timestamp) we want
|
||||
let unix_timestamp = value
|
||||
let timestamp_micros = value
|
||||
.as_date()
|
||||
.ok_or_else(|| TantivyError::InvalidArgument("invalid value".to_string()))?
|
||||
.into_unix_timestamp();
|
||||
if !self.is_noise_word(unix_timestamp.to_string()) {
|
||||
let term = Term::from_field_i64(field, unix_timestamp);
|
||||
.into_timestamp_micros();
|
||||
if !self.is_noise_word(timestamp_micros.to_string()) {
|
||||
let term = Term::from_field_i64(field, timestamp_micros);
|
||||
*term_frequencies.entry(term).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,7 +1068,6 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_json_field_possibly_a_date() {
|
||||
// Subseconds are discarded
|
||||
test_parse_query_to_logical_ast_helper(
|
||||
r#"json.date:"2019-10-12T07:20:50.52Z""#,
|
||||
r#"(Term(type=Json, field=14, path=date, vtype=Date, 2019-10-12T07:20:50Z) "[(0, Term(type=Json, field=14, path=date, vtype=Str, "2019")), (1, Term(type=Json, field=14, path=date, vtype=Str, "10")), (2, Term(type=Json, field=14, path=date, vtype=Str, "12t07")), (3, Term(type=Json, field=14, path=date, vtype=Str, "20")), (4, Term(type=Json, field=14, path=date, vtype=Str, "50")), (5, Term(type=Json, field=14, path=date, vtype=Str, "52z"))]")"#,
|
||||
@@ -1352,9 +1351,16 @@ mod test {
|
||||
query_parser.parse_query("date:18a"),
|
||||
Err(QueryParserError::DateFormatError(_))
|
||||
);
|
||||
assert!(query_parser
|
||||
.parse_query("date:\"1985-04-12T23:20:50.52Z\"")
|
||||
.is_ok());
|
||||
test_parse_query_to_logical_ast_helper(
|
||||
r#"date:"2010-11-21T09:55:06.000000000+02:00""#,
|
||||
r#"Term(type=Date, field=9, 2010-11-21T07:55:06Z)"#,
|
||||
true,
|
||||
);
|
||||
test_parse_query_to_logical_ast_helper(
|
||||
r#"date:"1985-04-12T23:20:50.52Z""#,
|
||||
r#"Term(type=Date, field=9, 1985-04-12T23:20:50Z)"#,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user