Boost exact artist name matches to top of search results
Fix short artist names (e.g. "ano") getting buried by wildcard matches. Re-ranks Spotify and iTunes results so exact name matches appear first, without changing what's returned.
This commit is contained in:
parent
694f190b6d
commit
97502ec600
2 changed files with 11 additions and 1 deletions
|
|
@ -603,6 +603,10 @@ class SpotifyClient:
|
||||||
artist = Artist.from_spotify_artist(artist_data)
|
artist = Artist.from_spotify_artist(artist_data)
|
||||||
artists.append(artist)
|
artists.append(artist)
|
||||||
|
|
||||||
|
# Re-rank: boost exact name matches to the top
|
||||||
|
query_lower = query.lower().strip()
|
||||||
|
artists.sort(key=lambda a: (0 if a.name.lower().strip() == query_lower else 1))
|
||||||
|
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -611,7 +615,10 @@ class SpotifyClient:
|
||||||
|
|
||||||
# iTunes fallback
|
# iTunes fallback
|
||||||
logger.debug(f"Using iTunes fallback for artist search: {query}")
|
logger.debug(f"Using iTunes fallback for artist search: {query}")
|
||||||
return self._itunes.search_artists(query, limit)
|
artists = self._itunes.search_artists(query, limit)
|
||||||
|
query_lower = query.lower().strip()
|
||||||
|
artists.sort(key=lambda a: (0 if a.name.lower().strip() == query_lower else 1))
|
||||||
|
return artists
|
||||||
|
|
||||||
@rate_limited
|
@rate_limited
|
||||||
def search_albums(self, query: str, limit: int = 10) -> List[Album]:
|
def search_albums(self, query: str, limit: int = 10) -> List[Album]:
|
||||||
|
|
|
||||||
|
|
@ -23358,6 +23358,9 @@ def search_artists_for_playlist():
|
||||||
'name': artist['name'],
|
'name': artist['name'],
|
||||||
'image_url': artist['images'][0]['url'] if artist.get('images') else None
|
'image_url': artist['images'][0]['url'] if artist.get('images') else None
|
||||||
})
|
})
|
||||||
|
# Re-rank: boost exact name matches to the top
|
||||||
|
query_lower = query.lower().strip()
|
||||||
|
artists.sort(key=lambda a: (0 if a['name'].lower().strip() == query_lower else 1))
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue