Innovations - Google Code Search Autocomplete

Google's new Code Search is all the rage these days. Here I present Google Code Search Autocomplete - my contribution to this already great service.

Think of it as adding functionality similar to what Google Suggest adds to the normal Google search.


To get the autocompleter, you must:
  1. Install the latest versions of Firefox and Greasemonkey (if you haven't already)
  2. Once in Firefox, navigate to the Google Code Search Autocomplete Userscript
  3. Install it as you would any userscript by clicking the "Install" button in the upper right-hand corner of the screen.
Once it's installed, head on over to Google's Code Search and give it a try.

Start typing in the search box to see the drop-down list of suggestions.

Developer Notes

This script does its dirty work by issuing an Ajax query behind the scenes for whatever you've typed so far plus the string "\w*". So if you had typed "google", the Ajax call would query for "google\w*". For readers unfamiliar with regular expressions, this basically means "google*" where * can be any number of "word" characters (A-Z, a-z and _).

The resulting page is then parsed for all instances of <b> tags with class="hl". These contain the query matches. Once collected, terms are then sorted and displayed to the user via the drop-down div below the search field.

Due to these design constraints, some of the script's behavior may seem strange at first. For example you may get only a handful of hits for "goo", but many for "google". This has to do with the number of redundant hits returned during the transparent Ajax request. The more reduntent matches there are, the fewer drop-down options there will be.

Also, since an entire page request is being made behind the scenes, the drop-down may feel slow to update. Especially if you're on a slower connection.


This article builds on concepts developed in a previous blog entry, in which I describe the process of incorporating the Scriptaculous library into Greasemonkey userscripts. Check it out if you'd like to learn more about the underlying mechanics of this script.

I hope you've found this useful or interesting. Drop me a line and let me know what you think!

digg this article


Lior said...

Hi, me again. Been following your work on the past so and so days.
Just wanted to say that this blog, unlike so many others, is shaping up to be very informative, interesting and well written, and overall quite a good resource for amateur programmers-tinkerers like myself. Keep up the good work! Such detailed and useful reviews are rare indeed on blogger.

Nice name for it, too.

jimbojw said...

Thanks! I appreciate the positive reinforcement. My goal is to put out several good articles each week on various topics - all related in some way to coding. I can't guarantee they'll all be good (or even interesting), but they'll contain original content.

BTW, I'm glad you like the name! I really hope Namco decides to make it a trilogy (even though the team's been disolved, I remain eternally hopeful).