Anup Khandelwal
Anup Khandelwal

Reputation: 365

Google custom search sort date range criteria not working

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

Upvotes: 30

Views: 1278

Answers (4)

Meghshyam Sonar
Meghshyam Sonar

Reputation: 301

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!

Upvotes: 0

user5809385
user5809385

Reputation:

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)}.

Upvotes: 2

Bhaskara Arani
Bhaskara Arani

Reputation: 1667

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

Upvotes: 1

JorgeObregon
JorgeObregon

Reputation: 3320

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

Upvotes: 1

Related Questions