2004-12-12

Hacking Google Suggest

Scoble->Nick Bradbury Nick Bradbury blogjáról kevertem ide:

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:

http://www.google.com/complete/search?hl=en&js=true&qu=keyword

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:

sendRPCDone(frameElement, "netcaptor", new Array("netcaptor", "netcaptor 7.5.3 crack", "netcaptor download", "netcaptor 7.5.3", "netcaptor crack", "netcaptor pro", "netcaptor 7.5.2", "netcaptor 7.5.3 serial", "netcaptor v7.5.3", "netcaptor review"), new Array("141,000 results", "169 results", "68,300 results", "2,890 results", "8,360 results", "56,500 results", "2,390 results", "213 results", "281 results", "15,900 results"), new Array(""));

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.

[Via Adam Stiles]
[Listening to: W.A.S.P = Helldorado - - W.A.S.P = Helldorado - (4:33)]