14 June 2006

Adding a Mozilla Search Engine

Gee, I'm a bit of a lazy bugger.

We have an internal application we use to enter/view/manage bugs. Not that we have any bugs of course. A bug is identified by a bug number, which can be supplied to our bugdb application and the relevant bug text displayed. Of course you can perform many more complex and combined forms of queries but the simple 'can you check this bug please' usually results in the simple bug number type of query.

It struck me that it'd be cool to somehow add our bugdb application as a search engine for Mozilla. So I could just enter the bug number in the search field and press enter, without needing to go to the actual bug application first.

Yes, I know. I must be really, really lazy.

I thought it'd be hard. I thought wrong. Those Mozilla people, what enablers!

If you look in the $MOZILLA_HOME/searchplugins directory, you'll probably see a bunch of files. The files ending with .src define a search plugin.

Looking at one of the .src examples, you can pretty easily see how it works.

For my bugdb search I really just needed to specify the URL of the bugdb application and specify the name of the query parameter it uses.

name="Oracle Bug DB"
description="Oracle Bug DB"

<input name="c_rptno" user>


You then save this as a .src file into the searchplugins directory, restart Mozilla and bango! you have a new search option.

How easy can it be!

I then hunted around and found some doc off the Mozilla website which actually explains how it all works. Good job Mozilla folks.

Even better, it shows how you can remotely install these things using a bit of JavaScript, which will add the .src file and an accompanying icon (16x16) to a client browser.

See http://mycroft.mozdev.org/deepdocs/installing.html#server which has a working example of the JavaScript calls:
"http://localhost.localdomain/plugins directory/"+name+".src",
"http://localhost.localdomain/plugins directory/"+name+"."+ext,
cat );

Now of course this is for our internal application, so it won't for you folks out there. But if you ever wanted to add a new option to the Mozilla search engine list, then try it out. No code required!

1 comment:

Andy said...

Brilliant! Now I just need to figure out how to do the same with IE7 (in combo with the Oracle Bug DB). Seems that the Opensearch spec is something I need to read (http://opensearch.a9.com/spec/1.1/description/)