Hack #96. Refine Your Google Search

Google might already know what keywords you should add to your search to find exactly what you're looking for.

As described in "Autocomplete Search Terms as You Type" [Hack #55] , you can visit http://www.google.com/webhp?complete=1 and start typing, and Google Suggest will autocomplete your query as you type. By itself, this is wickedly cool. Now, let's make it even cooler by integrating it into the main Google web search. Along with the usual search results, you'll see a list of related queries made up of additional keywords, so you can refine your search.

The Code

Google Suggest works by requesting a specially constructed URL with the characters you've typed so far. The request returns JavaScript code, and Google Suggest evaluates this code and adds the results to its autocomplete menu. If you type a complete keyword, followed by a space, Google Suggest will return a list of popular searches that include your keyword plus one or two other words.

For example, if you type firefox, Google Suggest constructs this URL:

	http://www.google.com/complete/search?js=true&qu=firefox

Enter that URL in your location bar and you'll see Google's response:

 sendRPCDone(frameElement, "firefox", new Array("firefox", "firefox download", "firefox browser", "firefox extensions", "firefox plugins", "firefox mozilla", "firefox themes", "firefox.com", "firefox web browser", "firefox 1.0"), new Array("25,900,000 results", "8,000,000 results", "6,990,000 results", "1,270,000 ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.