|
|
@@ -436,9 +436,9 @@ def validate_config(cfg):
|
|
|
if strategy not in {"weighted_average", "lexicographic"}:
|
|
|
raise ValueError("scoring.strategy must be 'weighted_average' or 'lexicographic'")
|
|
|
|
|
|
- within_hours = to_float_or_none(scoring.get("within_hours", 24))
|
|
|
- if within_hours is None or within_hours <= 0:
|
|
|
- raise ValueError("scoring.within_hours must be a positive number")
|
|
|
+ within_hours = to_float_or_none(scoring.get("within_hours", 0))
|
|
|
+ if within_hours is None or within_hours < 0:
|
|
|
+ raise ValueError("scoring.within_hours must be a non-negative number (0 = disabled)")
|
|
|
|
|
|
if strategy == "weighted_average":
|
|
|
weighted_fields = scoring.get("weighted_fields")
|
|
|
@@ -721,16 +721,18 @@ def rank_scored_records(records, scoring_cfg):
|
|
|
if not records:
|
|
|
return []
|
|
|
|
|
|
- within_hours = float(scoring_cfg.get("within_hours", 24))
|
|
|
+ within_hours = float(scoring_cfg.get("within_hours", 0))
|
|
|
strategy = str(scoring_cfg.get("strategy", "weighted_average")).strip()
|
|
|
prefer_lower = bool(scoring_cfg.get("prefer_lower", False))
|
|
|
tie_breakers = scoring_cfg.get("tie_breakers", [])
|
|
|
|
|
|
- now = dt.datetime.now(dt.timezone.utc)
|
|
|
- cutoff = now - dt.timedelta(hours=within_hours)
|
|
|
-
|
|
|
- recent = [r for r in records if r.get("created_at") is not None and r["created_at"] >= cutoff]
|
|
|
- candidates = recent if recent else records
|
|
|
+ if within_hours > 0:
|
|
|
+ now = dt.datetime.now(dt.timezone.utc)
|
|
|
+ cutoff = now - dt.timedelta(hours=within_hours)
|
|
|
+ recent = [r for r in records if r.get("created_at") is not None and r["created_at"] >= cutoff]
|
|
|
+ candidates = recent if recent else records
|
|
|
+ else:
|
|
|
+ candidates = records
|
|
|
|
|
|
default_lex_order = "asc" if prefer_lower else "desc"
|
|
|
|