Google Custom Search Sort by Date

Google generally sorts search results by relevance.  At times, it gives the option to sort by date.  Sometimes people want the definitive piece of information on a certain topic and other times they just want the most recent piece of information.

A few days ago I rolled out Google Custom Search on Streetsblog as an improvement from the default WordPress search.  It is a streamlined form of the Google search engine that integrates with our sites and displays results by relevance.  After I rolled it out, our editors immediately realized that they wanted to be able to see search results sorted by date as well as relevance.  So I set out to discover how to get Google Custom Search to sort by date.

It turns out that it wasn’t so hard.  I came across this thread explaining how to do it and modified the js code accordingly.  I then put an absolutely-positioned link on the search page:

The link toggles to “sort by relevance” when you are viewing results sorted by date.  Google estimates the date of a particular web page to the best of its ability using content on the page, its url and the first time it was crawled.  The search results appear to be “roughly” sorted by date.

Occasionally certain search results are listed higher than newer ones, perhaps when they are significantly more relevant.  For example, for the search on “bike lanes”, this post was listed above this post even though it was older than it, perhaps because it had 28 comments, much more than the 4 on the more recent post.

Still, hopefully this will meet the needs of our users and help them mine the thousands of posts on Streetsblog.

One Response to “Google Custom Search Sort by Date”

  1. Kai Says:

    We tried to get the Sort By Date implemented, however, sorting does not work correctly. Dates are mixed, see example: (click on the right “Relevance” → “Date”. You will see first 19 hours ago, second 1 hour ago, then 6 days ago, then 5 days ago.

    This is a real problem for our users. How can we solve this?
    You said “Occasionally certain search results are listed higher than newer ones, perhaps when they are significantly more relevant” but performing the search on the mentioned website shows all entries in correct date order.

    Thanks for any help,