Search code examples
c#bing-api

Bings Search API doesn't always return the same result count


If I do a search with Bings Webservice and search without specifying Offset and Count, I receive 98 results for my search. If I instead uses offset (as shown in the code below) total count is only 18.

Shouldn't the total count be the same if I specify offset or not?

    BingService soapClient = new BingService();

    SearchRequest request = new SearchRequest();
    request.AppId = ConfigurationManager.AppSettings["BingKey"];
    request.Sources = new BingLiveSearchService.SourceType[] { SourceType.Web };
    request.Query = query;
    request.Web = new BingLiveSearchService.WebRequest { Count = 20, Offset = 21, OffsetSpecified = true, CountSpecified = true };

    string resp = string.Empty;

    var response = soapClient.Search(request);
    if (response.Web != null && response.Web.Total > 0)
    {
        resp += "TOTAL COUNT:" + response.Web.Total + "<br/><br />";
        foreach (var item in response.Web.Results)
        {
            resp += "<div style='padding-bottom:10px;'> + item.Title + "</div>";
        }

    }

Solution

  • There are some words of warning in the API Basics documentation: "Depending on how popular a query is, the estimated number of results could be very different from the real number. Do not rely on this number for critical computation". I wonder if the count and offset arguments make the computation take slightly longer and so it is halted before as many results are gleaned? It is also worth note that the WebRequest.Count Property documentation mentions that "The minimum value for Count is 1; the maximum value is 50", so if you do specify a value for Count you are going to get less than the 98 results you have seen without specifying Count.