Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date range search using Google Custom Search API

I am using the Google Custom Search API to search for images. My implementation is using Java, and this is how I build my search string:

URL url = new URL("https://ajax.googleapis.com/ajax/services/search/images?"
                + "v=1.0&q=barack%20obama&userip=INSERT-USER-IP");

How would I modify the URL to limit search results, for example, to: 2014-08-15 and 2014-09-31?

like image 359
Amr Avatar asked Sep 04 '15 21:09

Amr


1 Answers

You can specify a date range using the sort parameter. For your example, you would add this to your query string: sort=date:r:20140815:20140931.

This is documented at https://developers.google.com/custom-search/docs/structured_data#page_dates

Also if you use Google's Java API you can use the Query class and its setSort() method rather than building the URL by hand.

like image 196
Terry Szymanski Avatar answered Sep 30 '22 15:09

Terry Szymanski