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 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:
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?
Unfortunately, there's not really much support for this in Spotify's Web API (I've tried myself, with the same outcome as you've had). And from the looks of it, the API's been worked on for a couple of years, so I wouldn't expect much to change.
However, I strongly recommend that you have a look at the Echo Nest API's instead; they support quite powerful queries and have a bunch of awesome stuff in their API. Furthermore, they've also got support for getting Spotify URI:s for the search results (tracks, artists etc). This means that you could probably stick to the EN API altogether.
Also, The Echo Nest are continuously adding more features to their API, so it's really become the go-to API for music (outperforming Last.fm and similar by far).
链接地址: http://www.djcxy.com/p/9458.html