Bing Search - Add query option with BingContainer.cs

Answered Bing Search - Add query option with BingContainer.cs

  • Tuesday, August 07, 2012 8:54 PM
     
      Has Code

    Hi -

    How can I add a query option that isn't included in the parameters of the method? for example:

    // Can't add "?$top=5" here or throws an exception string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure the bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey);

    // The Web method takes: query, market, adult, latitude, longitude, web file type. var webQuery = bingContainer.Web(query, null, null, null, null, null); // tried this - doesn't help anything webQuery.AddQueryOption("$top", 5); // neither webQuery.Expression nor webQuery.RequestUri shows "$top" Console.WriteLine(webQuery.Expression); Console.WriteLine(webQuery.RequestUri); // The query runs fine but isn't limted to 5 results

    As the code comments show, I tried to add a $top - doesn't work. Even though I used AddQueryOption (which seems like a winner), it doesn't change anything, doesn't affect the expression or Uri. Any ideas?

    Thanks - Victor David

All Replies

  • Tuesday, August 07, 2012 9:11 PM
     
     Answered Has Code

    I dug around in BingContainer to see how it was doing things. Need to use the return value from AddQueryOption to reassign the query object,  like so:

    // yay!
    webQuery = webQuery.AddQueryOption("$top", 5);

    That does it! Well, maybe that'll help somebody else.

    • Marked As Answer by VictorDavid Tuesday, August 07, 2012 9:11 PM
    •  
  • Wednesday, August 08, 2012 2:12 AM
    Moderator
     
     

    Hi,

    Thanks for sharing your experience.

    BR,

    Arwind


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework