javascript - 谷歌自定义搜索排序日期范围标准不起作用

标签 javascript api search google-custom-search

在 Google 自定义搜索中,我们在排序参数中传递日期范围条件

http://www.example.com/search?cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&q=google&sort=date:r:20160304:20160505.
https://developers.google.com/custom-search/docs/structured_search#restrict_to_range

但我们没有按照日期范围标准获得预期结果。 调试代码后,即使我们将排序参数传递到我们的搜索页面 url,排序参数也不会传递到自定义搜索 URL。

Google 自定义搜索网址:

https://cse.google.com/cse?q=google&r=m&cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&fexp=20606&client=google-coop&hl=en&type=0&oe=UTF-8&ie=UTF-8&format=p4&ad=p4&nocache=1081472127237880&num=0&output=uds_ads_only&source=gcsc&v=3&allwcallad=1&adext=as1%2Csr1%2Cctc1&bsl=10&u_his=50&u_tz=330&dt=1472127237882&u_w=1366&u_h=768&biw=1349&bih=233&psw=1349&psh=233&frm=0&uio=uv3st16sd13sv13lhsl1sr1cc1-&jsv=14100&rurl=http%3A%2F%2Fwww.example.com%2Fsearch%3Fcx%xxxxxxxxxxxxxxxxxxxx_yyyyy%26q%3Dgoogle%26sort%3Ddate%253Ar%253A20160304%253A20160505

但是当我们尝试使用排序日期范围参数访问直接 API 时,我们得到了预期的结果。

https://www.googleapis.com/customsearch/v1?q=google&cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&sort=date%3Ar%3A20160701%3A20160724&key=<APIKEY>

我们正在使用 Google 自定义搜索 V2 实现。

谢谢, 阿努普

最佳答案

尝试转义所有作为查询参数传递的特殊字符。例如

>  - &lt;
<  - &gt;
&  - &amp;
'  - &#039;
'' - &#034;

这些是这样编码的。你可以通过两种方式逃避它

  1. 明确指定 escapeXml = "**false**"因为默认值为 true。
  2. 如果您正在使用,请在 JSP 中添加 url <%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>然后通过调用逃脱 ${fn:escapeXml(myString)} .

关于javascript - 谷歌自定义搜索排序日期范围标准不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39264548/

相关文章:

javascript - 从浏览器启动 dialer.exe?

javascript - 从本地服务器访问 API

ios - 移动设备上的 Azure 应用服务身份验证问题

ruby-on-rails - 授予 API 访问 Rails 应用程序的最佳身份验证方法

javascript - 搜索具有许多记录的自动完成性能

javascript - Firefox 与 Chrome、Edge、Safari 之间的渲染差异

javascript - 从 $.post 返回值的变量范围问题

javascript - 哈皮,错误 415 : Unsupported Media Type error

php - 使用连接表从 POST 数组创建 MySQL 搜索查询

Java - 深度优先搜索