pub async fn search(
client: &SpotifyApi,
query: &str,
types: Option<&[&str]>,
limit: Option<u8>,
market: Option<&str>,
) -> Result<Option<Value>, HttpError>Expand description
Search the Spotify catalog
§Arguments
client- Authenticated Spotify clientquery- Search querytypes- Optional list of types to search (defaults to all)limit- Optional limit per type (default 20, max 50)market- Optional market (ISO 3166-1 alpha-2 country code) for content availability
§Market Parameter
The market parameter is important for podcast/episode searches. Without it, the Spotify API may return incomplete episode data (missing show information). When provided, episodes will include their parent show’s name and other metadata.
§Spotify API Quirk Workaround
The Spotify Search API has a known bug/quirk where requesting limit=1
returns different (often incorrect) results compared to limit=2.
For example, searching “tool” with limit=1 might return “Weezer” as the
top artist, but limit=2 correctly returns “TOOL” first, then “Weezer”.
This appears to be a ranking/relevance calculation issue on Spotify’s end where the algorithm behaves differently when only one result is requested.
Workaround: When limit=1 is requested, we actually fetch limit=2
from the API and then truncate the results to only return the first item.
This ensures consistent and correct “top result” behavior.
This workaround was implemented on 2025-01-12 after observing the issue. If Spotify fixes this behavior in the future, this workaround can be removed.