Monday 6 November 2017

Grouping operators in Spotify advanced search

I'm trying to use the Spotify web API to return multiple
specific results in one response.



For example,
maybe I want Spotify's detailed information for "Thriller", by Michael Jackson, and
"Highway Star", by Deep Purple.




Since
I don't already have the Spotify uris I need to use the Search method. And there's a
page describing Spotify's advanced search syntax href="http://www.spotify.com/us/about/features/advanced-search-syntax/"
rel="nofollow">here. They support searching against specific fields, like
track, artist, and album. They also support the basic boolean operators.



But there's nothing on that page (or anywhere
else on the internet, as far as I can tell) describing how the boolean operator
precedence works, or how you might go about grouping your search
criteria.



I would need something effectively the
same as (track:Thriller AND artist:"Michael Jackson") OR (track:"highway star" AND
artist:"Deep Purple").



Using similar criteria to
pull in just one track at a time works:



href="http://ws.spotify.com/search/1/track?q=track%3a%22thriller%22+AND+artist%3a%22michael+jackson%22"
rel="nofollow">http://ws.spotify.com/search/1/track?q=track:"thriller"+AND+artist:"michael+jackson"




I
tried to jump right in with the parentheses, even though they're not mentioned in the
docs. No
luck:



ws.spotify.com/search/1/track?q=(track:"thriller"+AND+artist:"michael+jackson")+OR+(track:"highway+star"+AND+artist:"deep+purple")



Then
I thought I'd try playing with precedence. Maybe they don't just process left-to-right -
maybe the ORs are all resolved, and then the
ANDs:



ws.spotify.com/search/1/track?q=track:"thriller"+OR+track:"highway+star"+AND+artist:"michael+jackson"+OR+artist:"deep+purple"



That
seemed promising, and returned 185 results, but it's not quite right. I'm seeing tracks
named "Highway Star" from other bands. That seems to rule out "left-to-right",
"OR-before-AND" AND "AND-before-OR". Which doesn't make any sense - what else is
left?




Can anyone with more Spotify
experience shed some light on how a query like this should work?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...