feat: instant local search results while full pipeline runs
Added SearchLocal() — queries only the FTS5 index with no network calls. The frontend now calls SearchLocal first, renders those results immediately (clearing the loading spinner), then fires the full Search() pipeline in the background. When full results arrive, they replace the local hits seamlessly. For indexed queries this means sub-100ms first results regardless of how slow MB/LB are. Unindexed queries still show the loading spinner until the full pipeline completes.
This commit is contained in:
@@ -112,6 +112,23 @@ func (e *Service) SearchRecordings(query string) ([]MBRecording, error) {
|
||||
return e.mb.SearchRecordings(e.ctx, query, mbSearchLimit)
|
||||
}
|
||||
|
||||
// SearchLocal queries only the local FTS5 index and returns results
|
||||
// instantly with no network calls. Returns nil if the index isn't
|
||||
// ready. The frontend calls this in parallel with Search() to show
|
||||
// instant results while the full pipeline runs.
|
||||
func (e *Service) SearchLocal(query string) *MBSearchResult {
|
||||
indexHits := e.index.Search(query, 30) //nolint:mnd
|
||||
if len(indexHits) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var result MBSearchResult
|
||||
mergeIndexHits(&result, indexHits)
|
||||
filterAndCap(&result)
|
||||
|
||||
return &result
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MusicBrainz lookup
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user