From 97502ec6008fa58f33b6d6655027430e0f737696 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 28 Feb 2026 08:41:19 -0800 Subject: [PATCH] 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. --- core/spotify_client.py | 9 ++++++++- web_server.py | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/spotify_client.py b/core/spotify_client.py index df2a3272..2d81eb81 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -603,6 +603,10 @@ class SpotifyClient: artist = Artist.from_spotify_artist(artist_data) 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 except Exception as e: @@ -611,7 +615,10 @@ class SpotifyClient: # iTunes fallback 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 def search_albums(self, query: str, limit: int = 10) -> List[Album]: diff --git a/web_server.py b/web_server.py index 55eb6d2c..619d5d03 100644 --- a/web_server.py +++ b/web_server.py @@ -23358,6 +23358,9 @@ def search_artists_for_playlist(): 'name': artist['name'], '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({ "success": True,