Retry indexer search with stripped parenthetical suffixes when initial query returns no results
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/claude-agent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+46
-11
@@ -588,23 +588,58 @@ func (service *MusicAgregatorService) searchIndexer(album *metadataPb.Album, tra
|
||||
artistName = album.GetArtists()[0].GetArtist().GetName()
|
||||
}
|
||||
|
||||
query := album.GetTitle()
|
||||
if artistName != "" {
|
||||
query = artistName + " " + query
|
||||
}
|
||||
|
||||
if tracker == "" {
|
||||
tracker = "all"
|
||||
}
|
||||
|
||||
result, err := service.indexer.Search(query, -1, tracker)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("query", query).Msg("indexer search failed")
|
||||
return nil, err
|
||||
title := album.GetTitle()
|
||||
queries := buildSearchQueries(artistName, title)
|
||||
|
||||
for _, query := range queries {
|
||||
result, err := service.indexer.Search(query, -1, tracker)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("query", query).Msg("indexer search failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug().Int("results", len(result.Items)).Str("query", query).Msg("indexer search completed")
|
||||
|
||||
if len(result.Items) > 0 {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
log.Debug().Str("query", query).Msg("no results, trying broader search")
|
||||
}
|
||||
|
||||
log.Debug().Int("results", len(result.Items)).Str("query", query).Msg("indexer search completed")
|
||||
return result, nil
|
||||
return &indexer.SearchResponse{}, nil
|
||||
}
|
||||
|
||||
func buildSearchQueries(artist, title string) []string {
|
||||
base := title
|
||||
if artist != "" {
|
||||
base = artist + " " + title
|
||||
}
|
||||
|
||||
queries := []string{base}
|
||||
|
||||
stripped := stripParenthetical(title)
|
||||
if stripped != title {
|
||||
q := stripped
|
||||
if artist != "" {
|
||||
q = artist + " " + stripped
|
||||
}
|
||||
queries = append(queries, q)
|
||||
}
|
||||
|
||||
return queries
|
||||
}
|
||||
|
||||
func stripParenthetical(s string) string {
|
||||
idx := strings.Index(s, "(")
|
||||
if idx > 0 {
|
||||
return strings.TrimSpace(s[:idx])
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (service *MusicAgregatorService) parseSearchResults(searchResult *indexer.SearchResponse, album *metadataPb.Album) []parsedItem {
|
||||
|
||||
Reference in New Issue
Block a user