feat: SearchIndex — background build + FTS5 query for popularity index

New SearchIndex struct in searchindex.go:
- Background build fetches top 1000 LB artists, then their top 10
  release groups and top 10 recordings (2001 API calls total)
- Dedicated 3 req/s rate limiter for indexer (LB allows 30/10s)
- Bounded concurrency (3 goroutines) with progress logging
- Batch INSERTs in transactions of 100 rows
- FTS5 query with prefix matching ('for you' → 'for* you*')
- Results sorted by popularity descending
- Skips rebuild if index is < 7 days old
- Marks index ready from existing rows if build fails
- Context cancellation for clean shutdown
This commit is contained in:
2026-03-25 09:39:22 -04:00
parent 57a07e96cb
commit bba4e1f3de
2 changed files with 691 additions and 0 deletions
+9
View File
@@ -29,6 +29,15 @@ func NewRateLimiter() *RateLimiter {
}
}
// NewRateLimiterN returns a rate limiter that allows n requests
// per second with a burst of n. Used for background tasks like
// index building where a higher rate is acceptable.
func NewRateLimiterN(n int) *RateLimiter {
return &RateLimiter{
limiter: rate.NewLimiter(rate.Limit(n), n),
}
}
// Wait blocks until the rate limiter allows the caller to proceed
// or the context is cancelled. Returns ctx.Err() if the context
// expires before a token becomes available.