Search has become an integral part of our lives and after the advent of Firefox (now IE7 too) the nifty search bar on the top-right seems to be a must have. With the plethora of engines that can be added to the existing list I have never come across the need to define one myself. But sometimes I think, “What if I could add this site to my search bar?”, incase an engine for such site does not exist. Well, here is my three part series on writing your own search engine plugin.

The Unavoidable Basics

The plugin source file is a normal text file with the extension .src. Every plugin starts with the tag,

< search

which has the following attributes,

version=”7.1″

the version indicates the latest version of Netscape against which the plugin was tested successfully. This means that the plugin won’t work for lower versions of Netscape. In Firefox specifying a version=”0.0″ indicates compatibility with all versions.

name=”plugin name”

this signifies the name of your plugin. This is the name visible in the search bar list.

description=”plugin description”

here goes the plugin description.

action=”url prefix”

Now pay attention! We need to examine the search url of the site we are building the plugin of. For example, Google has the search url which looks like “http://www.google.com/search?hl=en&q=semantic+void&btnG=Google+Search….” . The action represents the part of the url before ‘?’. So in our case it would be “http://www.google.com/search”.

searchForm=”form url”

An optional element referring to the form in the search page which submits the search.

queryCharset=”utf-8″

This specifies the charset to which the query belongs. If not specified the default charset of the browser is taken.

method=”GET”

Currently only the GET method is supported. Finally complete the search start tag.

>

Now we must define the search parameters to be passed to the search url.

< input name="query" user>

This represents the term that will be typed in by the end-user. Other parameters can also be passed by specifying another input tag, but they should have fixed values.

< input name="category" value="blog">

Then follows the input tag which is used to let the webmasters know where the search originated from.

< input name="sourceid" value="Mozilla-search">

Having configured the plugin we can now close the search tag.

< / search>

We are all done with creating a search plugin. The plugin source should look somewhat like the following:

< search version='7.1' name="plugin name" description="plugin description" action="url prefix" searchForm="form url" method="GET" >

< input name="query" user>
< input name="sourceid" value="Mozilla-search">

< /search>

You can use the plugin generator I created where you need to just fill in a few values and it spurts out the above code for you.

Incase you are hosting your plugin source somewhere and want the browser to automatically check for updates, you can do this using the browser tag. The browser tag follows after the search tag.

< browser updateIcon="url of plugin icon" updateCheckDays="10" >

The update attribute specifies the url of the plugin source file. The updateIcon specifies the url of the plugin icon if any. The updateCheckDays specifies the interval in days after which the browser should check for the update.

For manually installing the plugin you need to copy the src file into the searchplugins folder in the Firefox directory. The next part will introduce you the gory details.

  • http://www.ChiragMehta.info ChiragMehta

    Good One – posted the same on my blog with ur name as credit