refactor: make adapter .tier the single source of truth for ranking

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-10 19:07:58 +02:00
parent fbd6a056a4
commit d3bec2ee10
6 changed files with 14 additions and 19 deletions
+1
View File
@@ -31,6 +31,7 @@ class _BaseFake:
matched_album=target.album,
quality=_QUALITIES.get(self.name, _QUALITIES["youtube"]),
track_count=tracks,
source_tier=self.tier,
)
]
+1 -1
View File
@@ -127,7 +127,7 @@ def run_pipeline(
found: list[Candidate] = []
for adapter in adapters:
for c in adapter.search(target):
found.append(replace(c, confidence=score_confidence(target, c)))
found.append(replace(c, source_tier=adapter.tier, confidence=score_confidence(target, c)))
_persist_candidates(conn, job_id, found)
# 3. rank
+2 -9
View File
@@ -1,7 +1,5 @@
from lyra_worker.types import Candidate, Quality
_SOURCE_TIERS = {"qobuz": 0, "soulseek": 1, "youtube": 2}
def quality_class(q: Quality) -> int:
"""3 = hi-res lossless, 2 = CD lossless, 1 = lossy."""
@@ -13,11 +11,6 @@ def quality_class(q: Quality) -> int:
return 1
def source_tier(source: str) -> int:
"""Lower is better. Unknown sources rank worst."""
return _SOURCE_TIERS.get(source, 99)
def rank_key(c: Candidate) -> tuple[int, int]:
"""Sort key; larger is better. Quality class first, then source tier."""
return (quality_class(c.quality), -source_tier(c.source))
"""Sort key; larger is better. Quality class first, then source tier (from the adapter)."""
return (quality_class(c.quality), -c.source_tier)
+1
View File
@@ -26,6 +26,7 @@ class Candidate:
matched_album: str
quality: Quality
track_count: int
source_tier: int = 99
confidence: float = 0.0