【问题标题】:Google Search Engine returns only 10 results谷歌搜索引擎只返回 10 个结果
【发布时间】:2014-04-02 00:48:55
【问题描述】:

我有使用谷歌搜索引擎的 Java 应用程序。 Customsearch custom = new Customsearch(new NetHttpTransport(), new JacksonFactory(), httpRequestInitializer);

    Customsearch.Cse.List list = custom.cse().list("some query");
    list.setCx(cx);
    list.setKey(key);

   Search result = list.execute();
   List<Result> listResult =  result.getItems();

问题在于 listResult.size() = 10。无论实际结果有多少,它都会返回前 10 个结果。

请帮我解决这个问题!

【问题讨论】:

    标签: java google-app-engine google-search


    【解决方案1】:

    您没有设置要返回的结果数,默认为 10,此处为 api - https://developers.google.com/resources/api-libraries/documentation/customsearch/v1/java/latest/

    list.setNum(100);
    

    【讨论】:

    • 非常感谢!根据文档,每次我将 number 设置为 Customsearch.Cse.List 列表对象:例如 list.setNumber(100) 都会出现以下异常:线程“main”com.google.api.client.googleapis.json.GoogleJsonResponseException 中的异常: 400 Bad Request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "Invalid Value", "reason" : "invalid" } ], "message" : "Invalid Value" } at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145) 当数字大于 10 时会发生这种情况