Saturday 23 December 2006

Auto-discovery of Browser Search Plugins

The search box at the top of the page links into a Google Customised Search Engine that uses my Google Reader feed list's OPML as its definition so while searching it isn't quite as scary as actually searching my brain it will almost certainly find anything topical that I'm half likely to be interested in. The point of all this though was to have some raw material to play around with browser search plugins. The Amazon A9 OpenSearch standard\microformat defines a really neat little XML structure that should allow you to define a customised Search Engine plugin for all supported browsers. If you're using either FireFox 2 or IE 7 you should notice the following effects:

With FireFox 2 the Search Icon to the left of the default search box (circled in red below) should now be highlighted indicating that the browser has discovered a new search plugin. If you click the drop down to the right of the icon you will be presented with some options that now include adding "Search Joe Mansfield's Brain" which sets my CSE as the default and it will replace the default Search Icon with my mini-aegishjalmr icon to give you a visual clue about the new setting. I honestly wouldn't expect anyone to want to do this for anything other than academic curiosity.















On IE7 the effect is slightly different. Once again the changed UI element is circled in red. Again this can be expanded and the additional Search engine can be added.














All of this would be great if folks stuck to the spec but for some reason nothing ever seems to work out quite that simple. I've managed to hack together a combined XML that works for both browsers using the base A9 OpenSearch spec and one component ( moz:SearchForm ) defined by Mozilla's variant .

I found a couple of things that were useful along the way:
SearchPlugins.net provides a neat online utility for generating the whole thing. Sweet.
IE7's default "Find More Providers" option within the Search Dialog drop down links to the Microsoft "Add Search Providers to Internet Explorer 7" page which includes a nice simple online generator. It's not perfect but it does the job for IE7 and having it directly findable with just 2 clicks from within the browser is excellent.
However to get it to work (for me) for both browsers and have an Icon included for FF2 I had to do the following manually once I had the base XML file as produced by SearchPlugins.net:
  1. Add in xmlns:moz="http://www.mozilla.org/2006/browser/search/" to the OpenSearch Description namespace tag.
  2. Despite trying to get an image included by the generator I had to do this myself by adding in the image manually by pointing an image tag to raw data in the form of a 16x16 GIF with all non alphanumerics replaced with html escaped hex (i.e. the image tag content starts off with data:image/gif,GIF89a%10%00%... )
  3. Add in a moz:SearchForm tag pointing to the root of the CSE.
  4. The Searchplugins.net XML did not define the encoding type in the XML version header - IE7 didn't seem to like that so I put an encoding="UTF-8" back in there. Seemed to work.
You can find the whole thing here. No doubt I'll have to add some more to get it to work with Opera whenever I get around to testing that. Given that the final XML is only 11 lines long it seems to be that we have some more work to be done in getting this thing really "standardized" but maybe that's just me, eh?

Once you have your XML you need to host it somewhere and Blogger doesn't seem to give me the option so I threw mine up on the one of my Google Page Creator Pages. I then stuffed in a reference to this in the Blogger header code by using a link rel tag that I would show here if I could figure out how to quote raw html without borking this WYSIWYG posting thinggy. For those interested the place to insert the tag is around line 7 or so in the raw HTML just below the head tag and the Mozilla docs clearly describe how to format it.

No comments: