I have an application that is using the new Bing API from the Azure Datamarketplace. I used to be able to query the Bing API using a simple syntax using OR AND, etc. That doesn’t seem to work in the new API.
Old syntax:
“Jacksonville Jaguars” OR “NFL Jaguars” OR “Atlanta Falcons”
That would give me a query with any of those phrases (I am making a rt_Sports query for news).
I am calling HttpEncode on the query first, but am still not getting results. It works if I remove all the ” marks, but then I am getting results sometimes for news about Falcons and Jaguars (the animals)… Not what I wanted.
Anyone have any idea how you can form a query that takes multiple phrases?
I have tried to not use the OR, not use the ‘, use a “, use the | instead of OR. All of these work against BING the website, just not in the API.
I just tried this via Bing and got 36 Million results:
NFL Football | Seattle Seahawks | New York Giants | Dallas Cowboys | New Orleans Saints | New England Patriots | Jacksonville Jaguars
Same thing in the API returns 0.
I got an email from a friend who I also emailed this question out to and his thought was that I was going about it wrong. That there should be a way to form a LINQ query off the Bing object with multiple where clauses.
But I don’t see how that would be possible. You allow a BingSearchContainer and then call the News method on the container. The News method has only a single Query parameter.
var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search"));
bingContainer.Credentials = new NetworkCredential(App.BingAPIAccountKey, App.BingAPIAccountKey);
string unifiedQuery = "NFL Football | Jacksonville Jaguars | Atlanta Falcons";
var newsQuery = bingContainer.News(unifiedQuery, null, "en-US", "Strict", null, null, null, "rt_Sports", "Relevance");
newsQuery.BeginExecute(BingNewsResultLoadedCallback, newsQuery);
Try changing
unifiedQueryto the following:var unifiedQuery = "'NFL Football' or 'Jacksonville Jaguars' or 'Atlanta Falcons'";I tried something very similar to your sample code, using this format for the query string, and it worked for me:
Here are my results:
The format for the
unifiedQuerystring is basically the OData URI query string format. For a full description of how these query strings work, check out the OData URI conventions documentation at http://www.odata.org/documentation/uri-conventions.