[GH-ISSUE #268] Search doesn't appear to support field filters #146

Closed
opened 2026-02-27 23:21:04 +03:00 by kerem · 2 comments
Owner

Originally created by @InconsolableCellist on GitHub (Mar 28, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/268

The Spotify query API permits for field filters, which allow you to key a search down to return more specific results:

Field filters: By default, results are returned when a match is found in any field of the target object type. Searches can be made more specific by specifying an album, artist or track field filter. For example: The query q=album:gold%20artist:abba&type=album returns only albums with the text “gold” in the album name and the text “abba” in the artist name.

https://beta.developer.spotify.com/documentation/web-api/reference/search/search/

If you try to construct a query to the generic search() function and pass in a filter as part of your q parameter, the call to request() will URI encode it rather than treat it as additional parameters, mangling the query.

Originally created by @InconsolableCellist on GitHub (Mar 28, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/268 The Spotify query API permits for field filters, which allow you to key a search down to return more specific results: >Field filters: By default, results are returned when a match is found in any field of the target object type. Searches can be made more specific by specifying an album, artist or track field filter. For example: The query q=album:gold%20artist:abba&type=album returns only albums with the text “gold” in the album name and the text “abba” in the artist name. https://beta.developer.spotify.com/documentation/web-api/reference/search/search/ If you try to construct a query to the generic search() function and pass in a filter as part of your q parameter, the call to request() will URI encode it rather than treat it as additional parameters, mangling the query.
kerem 2026-02-27 23:21:04 +03:00
Author
Owner

@InconsolableCellist commented on GitHub (Mar 29, 2018):

I found a workaround that I didn't think previously worked, due to a typo. You can use the q parameter in the generic search() function to compose the filter yourself. For example:

q set to "steambreather artist:mastodon" will work.

I previously ruled this out by trying to compose it like "steambreather&artist:mastdon"

Functions could be added to support this so that the end user doesn't have to compose the filter himself, however, as currently this workaround makes the consumer responsible for making some Spotify-API-specific code himself.

<!-- gh-comment-id:377085744 --> @InconsolableCellist commented on GitHub (Mar 29, 2018): I found a workaround that I didn't think previously worked, due to a typo. You can use the q parameter in the generic search() function to compose the filter yourself. For example: q set to "steambreather artist:mastodon" will work. I previously ruled this out by trying to compose it like "steambreather&artist:mastdon" Functions could be added to support this so that the end user doesn't have to compose the filter himself, however, as currently this workaround makes the consumer responsible for making some Spotify-API-specific code himself.
Author
Owner

@stephanebruckert commented on GitHub (Jan 11, 2020):

Yes everyone is free to build custom queries. A first step could be to document how to write a query in the spotipy doc.

<!-- gh-comment-id:573340864 --> @stephanebruckert commented on GitHub (Jan 11, 2020): Yes everyone is free to build custom queries. A first step could be to document how to write a query in the spotipy doc.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#146
No description provided.