Results filtered by Date Range - Even WebSearchResults

Feb 27, 2009 at 8:19 PM
Edited Feb 27, 2009 at 8:19 PM
Well, that's a few hours of my life I'll never get back.

I started off trying to get the Scoring=Date to work on Web Results, as it does with News, Blogs, etc. - but no luck.  Seems Google's left that functionality out all together.

You can however, filter your results to only return those that were indexed within a certain date range.

The syntax goes like this:
 
WebSearchOptions webSearchOptions = new WebSearchOptions();
SearchResults
searchResults = Searcher.Search(webSearchOptions, "\"Yamaha Motorcycle\" daterange:2450958-2450968");

That also works if you just punch it into the google.com search.  So, you dont add it as a query parameter - instead it gets embedded in the search string.

The following two links got me started:
http://groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/aceabadcc922580/99c7feafb6cee4a4?lnk=gst&q=web+search+advanced
http://reviews.cnet.com/4520-10165_7-6206764-2.html

The catch is that you need to represent the date range as a Julian date. 

A function to do this can be found here:
http://dotnetblogger.com/post/2009/02/26/Convert-DateTime-to-Julian-Date-in-C.aspx

And you're away!

Localman
Simple Sales Tracking
Feb 27, 2009 at 8:40 PM
Edited Feb 27, 2009 at 8:41 PM
Should mention also - Google doesnt take into account anything after the '.' in a Julian date, which represents Hours, Seconds, Minutes...  So, when you're creating the dates, round the number to 0 decimal places.

For example, the following line would return everything indexed over the last 24 hours:

 

WebSearchOptions webSearchOptions = new WebSearchOptions();

string searchTerms;

searchTerms =
"\"Yamaha Motorcycle\" daterange:" + Math.Round(GetJulianDate(DateTime.UtcNow.AddDays(-1)), 0) + "-" + Math.Round(GetJulianDate(DateTime.UtcNow), 0);

SearchResults searchResults = Searcher.Search(webSearchOptions, searchTerms);