Search the Long Tail of Code

tagged: google coop search code

I'm announcing a new feature to ViNull.com tonight, though it's been up for a few days now: ViNull Blogger's Code Search.  Based on a Google Co-op search, this search will search .NET blogs that regularly post code examples and tutorials. Why is this helpful?  Well, sometimes you are just searching how a control or class in the framework works.  In that case, Google is great.  Other times, you find yourself faced with a tricky bit of code, and the MSDN documentation is lacking.  In this case you need to find that guy's blog who had the same problem and see how he solved it.  Google is no help, it doesn't understand this is a very special set of circumstances and the front page is dominated with MSDN, asp.net, and lord knows how many splogs and sites scraping content from the newsgroups (sorry Experts Exchange, no one is signing up to see the solution).

To make the search handy, along with adding a search box in the side bar I've made an OpenSearch plugin that works in IE7 and FireFox 2.0 and any other browsers supporting the format.  You can install it by clicking the link on the search page, or if you are anywhere on the site you'll have an option in your search "drop down" list to add the engine.

Embedding the search in an ASP.NET page does have it's quirks.  The Google supplied code wants a special form id set and this conflicts with the form id generated by .NET.  If you're using master pages, you can't change the Page.Form.ID from "aspnetForm" - a hard coded value (some would call this a bug, but I'd say it's a lazy developer to hard code it in the first place).  Now, you could get crazy like Jon Sagara did try and force the issue.  Sometimes, like Mr. Sagara, we can't see the forest for the trees.

Since we are already requiring JavaScript to run the search in the first place, we can just add some JavaScript of our own right before the Google code.  In my case, it was the few lines below.

<script language="javascript" type="text/javascript">
  document.forms.aspnetForm.id = "searchbox_013071147134056726688:i9pf1xip1xq";
  document.forms.aspnetForm.method = "get";
</script>

One last note, this search only works if I build a list of decent, code-laden .NET blogs.  If you know of a coder who needs to be on the list, let me know.

2 Comments

On Dec 5, 2006 5:16 AM Lucas said...
Nice to see someone finding a good use for Google Coop and Google's custom search feature.

This is the first time I've come across OpenSearch. Looks interesting, although I'm not totally sure I understand what it is on first glance. OpenSearch's self-described 'OpenSearch is a collection of simple formats for the sharing of search results' doesn't tell me much.
On Dec 5, 2006 6:05 AM Mike said...
Thanks for the comment Lucas.

OpenSearch is the just the format for custom search engines in your browser (the little search box in the top right of FF2 and IE7). The reason I called it out by name is both FF and IE are supporting the format.

Leave a comment



Your name:
 

Your email (not shown):
 

Your website (optional):