How to get the next page of results from Bing Search Container in C#?

842 Views Asked by At

I am using the BingSearchContainer.cs with a Winform in C#. I am returning the results using the following code. After a good couple of hours looking I can't figure out how to return the other pages of results. It is only possible to return a maximum of 50 results at a time. I would like to return more pages and then add these to "imageSet" to have a full list of resulting images. Any hints or pointers would be really useful, thanks in advance for any help.

void bingSearch(string searchTerm)
        {
            try
            {
                imageSet = new List<Bing.ImageResult>();
                const string bingKey = "[key]";
                var bing = new BingSearchContainer(
                new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(bingKey, bingKey) };                
                var query = bing.Image("\"" + searchTerm + "\"" + "(" + site1 + " OR " + site2 + ")", null, null, null, null, null, ImageFilters);
                Debug.Print("Full Search: " + query.ToString());
                query = query.AddQueryOption("$top", 50);
                query = query.AddQueryOption("$skip", 20);
                var results = query.Execute();
                int index = 0;
                foreach (var result in results)
                {
                    imageSet.Add(result);
                    Debug.Print("URL: " + imageSet[index].MediaUrl);
                    index++;
                }
                Debug.Print("Results: " + imageSet.Count);
            }
            catch
            {
                Debug.Print("Error");
            }
        }
1

There are 1 best solutions below

0
On

Solved this.

Actually it is very simple. The "$skip", 20 query option sets the off-set for the pages such that if I have an off-set of 0 I get the first 50 images, an off-set of 50 I get the next 50 images and so on.