« Making Sure Your Visitors Can't Buy | Main | Hack Yourself »
December 10, 2004
Hacking Google Suggest
Google's Suggest feature is lighting up the blogosphere these days. It functions as like autocomplete for your search box, where Google attempts to determine what you are searching for and gives you suggestions. Web tinkerer that I am, I had to dig in a little and see how this works.
At its simplest, Google Suggest is javascript code that looks at what you are typing in the Google search box. When you press a key, GS phones home and passes the current contents of the search box. The server returns some suggestions are then displayed to the user. The javascript code is a little obfuscated, more to keep the size down than to obscure the contents. You can look at it here.
The script handles the onkeydown event of the search box. When that fires, it grabs the contents of the search box and sends the contents to a Google server for suggestions.
A request to the suggestion server looks like this:
In return, the suggestion server returns some results as javascript. Here are the results that get returned when I have typed "netcaptor" in the box:
Cool, huh?
Hacked appropriately, this could be a cool tool for generating related searches to a given keyword. Here's a quick, first attempt - I put together some sample code that grabs Google's suggestion for a given keyword (or partial). GPL'ed PHP source code is included.
Oh yeah - you might be interested in my earlier post about hacking Adsense for Feeds.

No comments:
Post a Comment