Question

I am using the Google C# API for the Custom Search and have it working and returning results, however I cannot see a way to make the paging work correctly.

Looking at what I get returned, no where does it tell me how many pages there are in the result? It just has a .Start property? Which is not much good unless I know how many 'pages' of results I have?

Am I missing something stupid here? Here is an example of the code I have so far

        var svc = new CustomsearchService(new BaseClientService.Initializer { ApiKey = settings.GoogleCustomSearchApi });
        var listRequest = svc.Cse.List(searchTerm);

        listRequest.Cx = settings.GoogleCustomSearchEngineId;
        listRequest.ImgSize = CseResource.ListRequest.ImgSizeEnum.Medium;
        listRequest.Num = 10;

        // List to hold everything in
        var resultItems = new List<Google.Apis.Customsearch.v1.Data.Result>();

        // Result set 1
        listRequest.Start = 1;
        var search = listRequest.Execute();
        resultItems.AddRange(search.Items);

I have resulted at the moment to doing two or three calls one after the other and getting a load of results back. But I would prefer to have this properly paged.

Was it helpful?

Solution 2

Found it, its in

search.SearchInformation.TotalResults

OTHER TIPS

The JSON API response has totlResults field: https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response. It should be exposed under search.Queries

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top