Google自定义网站搜索Api C#Paging

时间:2013-11-05 20:37:56

标签: c# search-engine google-custom-search

我正在使用Google C#API进行自定义搜索并使其正常工作并返回结果,但是我看不到让分页正常工作的方法。

看看我得到了什么,没有在哪里告诉我结果中有多少页?它只有一个.Start属性?除非我知道我有多少“页面”结果,否则哪个不太好?

我在这里错过了一些愚蠢的东西吗?这是我到目前为止的代码示例

        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);

我现在已经一个接一个地进行了两次或三次调用并获得了大量结果。但我更愿意正确分页。

2 个答案:

答案 0 :(得分:3)

JSON API响应有totlResults字段: https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response。 它应该在search.Queries

下公开

答案 1 :(得分:3)

找到它,它在

search.SearchInformation.TotalResults