Answered How to form a complex query?

  • Monday, August 13, 2012 10:14 PM
     
      Has Code

    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.

    This is an example of my query.

    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);
    

    It appears as though you can only make a single query at a time, and the assumption is that it is always a phrase. Is that correct?


    Jason Short

All Replies

  • Monday, August 13, 2012 11:42 PM
     
     

    Hi Jason -

    I think the clue is your statement:

    I am calling HttpEncode on the query first..

    BingContainer does the encoding for you.  When I tried that (double encoding), I got zero results too. Otherwise I do get results. Maybe not the ORs you wanted, I didn't drill into that much, but try passing the query to BingContainer without encoding it and see if that helps.

    Victor David

  • Tuesday, August 14, 2012 4:58 PM
     
     Answered

    Yes, I tried that too.  I looked at the code and noticed it was encoding the query, but it looks like it is only encoding for a single phrase.  From what I gather there is no way to make multiple queries in a single statement like with the old system.  It appears from everyone I have talked to that I need to make several queries and aggregate the results myself.


    Jason Short