fix: library bonus as post-normalization additive, not pop contamination
The +10M library bonus was added directly to the popularity map, which made it the maxPop normalization denominator. With maxPop=10M, every non-library artist's log-normalized popularity collapsed to near-zero, making their blended score purely 40% of MB relevance. All non-indexed artists scored ~35 and ranked by MB noise. New approach: - Removed +10M from both GetPopularityBatch and boostWithPopularity - GetPopularityBatch now returns PopularityBatchResult with separate Popularity and InLibrary maps - rerankArtists takes a libraryMBIDs set and applies a fixed +25 score bonus AFTER blended scoring and normalization - maxPop reflects real popularity only, so log normalization works correctly across all artists Shannon Wright (766K listens) now properly outranks Shannon Kennedy (95 listens) because the popularity scale isn't contaminated.
This commit is contained in:
@@ -316,9 +316,15 @@ func (si *SearchIndex) GetPopularity(mbid string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetPopularityBatch returns popularity (listen count) for multiple
|
||||
// MBIDs in a single query. Returns a map of MBID → popularity.
|
||||
func (si *SearchIndex) GetPopularityBatch(mbids []string) map[string]int {
|
||||
// PopularityBatchResult contains popularity and library status.
|
||||
type PopularityBatchResult struct {
|
||||
Popularity map[string]int
|
||||
InLibrary map[string]bool
|
||||
}
|
||||
|
||||
// GetPopularityBatch returns popularity (listen count) and library
|
||||
// status for multiple MBIDs in a single query.
|
||||
func (si *SearchIndex) GetPopularityBatch(mbids []string) *PopularityBatchResult {
|
||||
if len(mbids) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -341,7 +347,10 @@ func (si *SearchIndex) GetPopularityBatch(mbids []string) map[string]int {
|
||||
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
result := make(map[string]int, len(mbids))
|
||||
result := &PopularityBatchResult{
|
||||
Popularity: make(map[string]int, len(mbids)),
|
||||
InLibrary: make(map[string]bool),
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
var mbid string
|
||||
@@ -349,13 +358,13 @@ func (si *SearchIndex) GetPopularityBatch(mbids []string) map[string]int {
|
||||
var inLib int
|
||||
|
||||
if err := rows.Scan(&mbid, &pop, &inLib); err == nil {
|
||||
existing, ok := result[mbid]
|
||||
existing, ok := result.Popularity[mbid]
|
||||
if !ok || pop > existing {
|
||||
if inLib == 1 {
|
||||
pop += 10_000_000 //nolint:mnd // library bonus
|
||||
}
|
||||
result.Popularity[mbid] = pop
|
||||
}
|
||||
|
||||
result[mbid] = pop
|
||||
if inLib == 1 {
|
||||
result.InLibrary[mbid] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user