Problem with BingSearchContainer.cs - Composite query

Answered Problem with BingSearchContainer.cs - Composite query

  • Tuesday, August 07, 2012 11:01 PM
     
      Has Code

    Hi -

    I'm trying to make a composite query using the BingSearchContainer.cs. The query itself is fine, but I can't access the results. There seems to be a problem with the IEnumerator:

    // This is fine
    var compositeResults = compositeQuery.Execute();
    // Accessing the enumerator throws with:
    //  The closed type Bing.ExpandableSearchResult does not have a corresponding WebTotal settable property.
    foreach (var result in compositeResults)
    {
    }
    // or if I try this:
    var x = compositeResults.GetEnumerator();
    // then this statement throws
    x.MoveNext();

    How do I access the results? In the above foreach loop, Intellisense shows that result contains collection properties (result.Web, result.Image, etc) as I expected, but compositeResults itself throws when I try to drill into it.

    Ideas? Thanks..

    Victor David


    • Edited by VictorDavid Tuesday, August 07, 2012 11:02 PM
    •  

All Replies

  • Wednesday, August 08, 2012 1:05 AM
    Owner
     
     

    This blog entry has a good description of how to use it with Metro style apps:

    http://blogs.msdn.com/b/dau-blog/archive/2012/06/11/async-bing-for-metro-style-apps.aspx

    Thanks,

    Max

  • Wednesday, August 08, 2012 6:23 AM
     
     

    Hi Max -

    The app discussed in the blog entry does not do a composite query. At least I didn't see that. It makes an Image query and a Web query. All my singular queries (Web, Image, etc) work fine and I'm able to iterate the return object to display the individual results. And my composite query (that is, the query itself) also works fine, but throws an exception when I iterate its results object.

    Victor David





    • Edited by VictorDavid Wednesday, August 08, 2012 6:45 AM
    •  
  • Wednesday, August 08, 2012 7:24 AM
     
     Answered

    Update: I downloaded BingSearchContainer.cs again and noticed that the new version now includes the property (and other properties) for ExpandableSearchResult that the exceptions I was getting were complaining about. The new version also introduces breaking changes in its API - it adds new parameters in the bingContainer.Web, bingContainer.Image, etc. methods for setting options. That's good, but the method parms are now in a different order; so if you decide to use this new version of BingSearchContainer, you'll have to update the places you're using it.

    Victor David



    • Edited by VictorDavid Wednesday, August 08, 2012 8:05 AM
    • Marked As Answer by VictorDavid Wednesday, August 08, 2012 8:06 AM
    •  
  • Wednesday, August 08, 2012 4:04 PM
    Owner
     
     

    Sorry, looks like I misread your previous question (I thought you were looking for an example of how someone used BingSearchContainer.cs), but here's a follow up one.

    When you are talking about the newer version, when did you last download the one that did not contain the ExpandableSearchResult properties? The BingSearchContainer.cs is auto-generated and describes the schema of the API, so if you downloaded the file before we supported Composite, than indeed you would have such issues.

    Thanks,

    Max

  • Wednesday, August 08, 2012 5:20 PM
     
     

    Hi Max -

    I started working with Azure Bing in June and downloaded the .cs file maybe in mid June. The docs talked about Composite at that time, but I didn't really get into Composite via C# until yesterday. 

    Well, it's working now - and was an easy fix :)

    Victor David

  • Wednesday, August 08, 2012 5:28 PM
    Owner
     
     

    Ah, ok, we kept improving the schema and the file until late July :)

    Thanks,

    Max

  • Friday, August 10, 2012 12:50 AM
     
      Has Code

    Hi Victor,

    One thing to keep in mind is that when you new-up a service container instance, it has IgnoreMissingProperties == false so any change to the entity-set (even adding properties to it) would cause an exception in the code.

    You could easily fix that by setting serviceContainer.IgnoreMissingProperties = true; after newing-up the instance before enumerating it.

                var serviceContainer = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/v1/"));
                serviceContainer.IgnoreMissingProperties = true;
                serviceContainer.Credentials = new NetworkCredential("User", "AccountKey");
    
                var compositeResult = serviceContainer.Composite("web", "xbox", null, null, null, null, null, null, null, null, null, null, null, null, null).Execute().First();
                foreach (var result in compositeResult.Web)
                {
                    Console.WriteLine(result.Title);
                }
    
    Ziv.