Recency component in [0, 1]: 1.0 for "just updated", halving every [`RECENCY_HALF_LIFE_DAYS`]. Unparseable timestamps score 0.
(updated_at: &str, now: chrono::DateTime<chrono::Utc>)
| 584 | /// Recency component in [0, 1]: 1.0 for "just updated", halving every |
| 585 | /// [`RECENCY_HALF_LIFE_DAYS`]. Unparseable timestamps score 0. |
| 586 | fn recency_score(updated_at: &str, now: chrono::DateTime<chrono::Utc>) -> f64 { |
| 587 | let Ok(updated) = chrono::DateTime::parse_from_rfc3339(updated_at) else { |
| 588 | return 0.0; |
| 589 | }; |
| 590 | let age_days = (now - updated.with_timezone(&chrono::Utc)).num_seconds() as f64 / 86_400.0; |
| 591 | if age_days <= 0.0 { |
| 592 | return 1.0; |
| 593 | } |
| 594 | 0.5_f64.powf(age_days / RECENCY_HALF_LIFE_DAYS) |
| 595 | } |
| 596 | |
| 597 | /// Combine the candidate score parts into the final ranking score. |
| 598 | fn final_score(candidate: &CandidateScore, recency: f64) -> f64 { |
no outgoing calls