kaaes / spotify-web-api-android

A wrapper for Spotify Web API. It uses Retrofit to create Java interfaces from API endpoints
http://kaaes.github.io/spotify-web-api-android
MIT License
381 stars 138 forks source link

Loose Search Results #15

Open ryandt opened 9 years ago

ryandt commented 9 years ago

After doing a few search tests, I've come across some unexpected results. When searching for a particular track, I am receiving results that were queried against other fields besides just the track name (e.g. album or artist name) even though my query exclusively contains the "track" criteria. For example, when executing a search query for tracks on the string "blind", three out of four of the tracks returned do not contain any of the characters of the string "blind" in the track name. Instead, the results seem to also be querying artist and album names as "blind" appeared in either or both of them.

I initially brought up this issue on the web API discussion board, and Michael Thelin's (mod) suggestion was to add a track variable to the search query, e.g. https://api.spotify.com/v1/search?type=track&q=track:blind. He mentioned that he will be clarifying the search documentation to better define this.

Could this track variable be added to the web wrapper's search model so that we can return more well-defined search results?

JohnnyCrazy commented 9 years ago

There already exists a way to only search for tracks searchTracks(...),

searchTracks(...)
searchArtists(...)
searchAlbums(...)
searchPlaylists(...)

It will set the type-parameter in the query (source)

ryandt commented 9 years ago

@JohnnyCrazy When searching by either of the search methods available in this wrapper, you'll notice that the search criteria are loosely filtered. For example, if you invoke searchTracks(...) with the query string "colour", the top three results do not contain the string "colour" in the track name. Instead, "coulor" is being filtered from the results' artist and album names.

thelinmichael commented 9 years ago

As @JohnnyCrazy mentions, any string that's passed as a parameter to searchTracks will be passed to the Spotify Web API, so passing "track:blind" should be the equivalent to the URL you've given in your post.

The assumption that the API only returns tracks that has parts of the query in its name is, as you've discovered, wrong. A similar behaviour can be found while searching playlists, as you may get results where the playlist's description matches the search query, but not the playlist's name. In this case the client has to filter out unwanted results. I can understand why being able to let Spotify's API do this filtering would be a good feature though.

JohnnyCrazy commented 9 years ago

So for your example @ryandt , you could use the following call:

//This will only contain Tracks with "colour" in their name
TracksPager pager = searchTracks("track:colour");
ryandt commented 9 years ago

@thelinmichael, if you execute a query with with the track variable defined vs. no track variable defined, you will receive different results. For example, please compare the link query link above to a query with a value of "blind" and with no track variable defined.

@JohnnyCrazy, searchTracks("track:colour") looks like it may work as a workaround, but I'm not in a location to test it at this time. I will give it a try later today. Thanks for the suggestion.

Update: After doing a test on the suggestion above, it appears that the wrapper model will return return strict search results when the track (or other item type) variable is prepended to the query string. Cheers!

thelinmichael commented 9 years ago

@ryandt, Indeed! My point is that these two queries represent different client intentions, one that wants to retrieve everything related to 'colour' (i.e. any album, artist, track name, and perhaps other attributes), and one that only wants to retrieve tracks where there's a direct match to the name.

kaaes commented 9 years ago

Interesting discussion! Seeing that query parameter can get pretty complex I think it would be useful to have some kind of a builder for it.