Skip to content

Commit 918a37a

Browse files
committed
use datetime's timestamp as seconds
1 parent 2facace commit 918a37a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ impl FormulaScorer<'_> {
167167
// Convert from i64 to f64.
168168
// f64's 53 bits of sign + mantissa for microseconds means a span of exact equivalence of
169169
// about 285 years, after which precision starts dropping
170-
Ok(datetime.timestamp() as PreciseScore)
170+
let float_micros = datetime.timestamp() as PreciseScore;
171+
172+
// Convert to seconds
173+
let float_seconds = float_micros / 1_000_000.0;
174+
175+
Ok(float_seconds)
171176
}
172177
ParsedExpression::Mult(expressions) => {
173178
let mut product = 1.0;
@@ -522,7 +527,7 @@ mod tests {
522527
// datetime expression constant
523528
#[case(
524529
ParsedExpression::DateTime(DateTimeExpression::Constant("2025-03-18".parse().unwrap())),
525-
Ok("2025-03-18".parse::<DateTimePayloadType>().unwrap().timestamp() as PreciseScore)
530+
Ok("2025-03-18".parse::<DateTimePayloadType>().unwrap().timestamp() as PreciseScore / 1_000_000.0)
526531
)]
527532
// datetime expression with payload variable that doesn't exist in payload and no default
528533
#[case(
@@ -536,7 +541,7 @@ mod tests {
536541
// datetime expression with payload variable that doesn't exist in payload but has default
537542
#[case(
538543
ParsedExpression::DateTime(DateTimeExpression::PayloadVariable(JsonPath::new(NO_VALUE_DATETIME))),
539-
Ok("2025-03-19T12:00:00".parse::<DateTimePayloadType>().unwrap().timestamp() as PreciseScore)
544+
Ok("2025-03-19T12:00:00".parse::<DateTimePayloadType>().unwrap().timestamp() as PreciseScore / 1_000_000.0)
540545
)]
541546
#[test]
542547
fn test_default_values(

0 commit comments

Comments
 (0)