最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google custom search sort date range criteria not working - Stack Overflow

programmeradmin0浏览0评论

In Google Custom search we pass date range criteria in sort parameter

:yyyyyy_yyyyy&q=google&sort=date:r:20160304:20160505.

But we are not getting expected result as per the date range criteria. After debugging the code the sort parameter is not getting passed to custom search URL even when we are passing it on to our search page url.

Google Custom search URL:

;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%2Fsearch%3Fcx%xxxxxxxxxxxxxxxxxxxx_yyyyy%26q%3Dgoogle%26sort%3Ddate%253Ar%253A20160304%253A20160505

But when we try to access the direct API with sort date range parameter we are getting expected results.

;cx=xxxxxxxxxxxxxxxxxxxxx:yyyyyy_yyyyy&sort=date%3Ar%3A20160701%3A20160724&key=<APIKEY>

We are using Google custom search V2 implementation.

Thanks, Anup

In Google Custom search we pass date range criteria in sort parameter

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

But we are not getting expected result as per the date range criteria. After debugging the code the sort parameter is not getting passed to custom search URL even when we are passing it on to our search page url.

Google Custom search URL:

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

But when we try to access the direct API with sort date range parameter we are getting expected results.

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

We are using Google custom search V2 implementation.

Thanks, Anup

Share Improve this question edited Oct 21, 2016 at 6:14 Anup Khandelwal asked Sep 1, 2016 at 6:53 Anup KhandelwalAnup Khandelwal 3652 gold badges6 silver badges23 bronze badges 1
  • 1 It will be helpful to share your JavaScript codes (for the generation of the Google Custom search URL) so the community could look closely for a possible fix. – nyedidikeke Commented Sep 14, 2016 at 0:36
Add a comment  | 

4 Answers 4

Reset to default 2

Try to escape all special characters which are passed as query parameters. For example

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

These are encoded like this. You can escape it in two ways

  1. explicitly specifying escapeXml = "**false**" as the default value will be true.
  2. Add the url in JSP if you are using <%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> and then escape by calling ${fn:escapeXml(myString)}.

It seems like an issue with your url parameters encoding. It might be double encoded.

I think in code ur doing any escape characters for the query params try to remove that check

Make sure you're using correct format.

https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=searchterm&sort=document-weight

Thanks!

发布评论

评论列表(0)

  1. 暂无评论