Sunday, October 18, 2009

Add Search Engine - Firefox and IE7

Artifacts (Issues, comments, discussions) drive most of what we do at my day job. During an iteration meeting today, I found that most of us know the artifact id for getting to a page but the route to get to that page is atleast 2 clicks away (2 clicks before you get to the page to enter artifact id and one more to get to the actual page). I was wondering if it would be possible to use the "search engine" helpers that are available in Firefox 2 and IE 7. That would just make us enter the artifact id in the "Search engine" box and it takes us directly to that page (ofcourse after you login once to the application).

Luckily the OpenSearch Specification helps us here. Just Create an xml that adheres to the Opensearch specification and loading that page in both Firefox(2 and above) and IE(Version 7 and above) adds those to the list of search engines managed by your browser. There is a good tutorial at mozilla developer center. Ill cover the basics here. If you are interested, I can even make an application that lets you fill in the details and will post the xml file that you can use for adding your own search engine. Please add a comment if you are interested.

Without further ado, here is the minimal template for the xml file
  
  
      Some Short Name that appears in the Search Engines box
      Long Description
      
  
Call this file, say, plugin.xml in your web root directory. For a simple Apache server install, place this in /var/www (or whatever your DocumentRoot is). An example of the template modified for Google Search Engine is shown below

      My Google
      Google search implemented as firefox addon
      

Save that as google-plugin.xml. The thing to note above is the {searchTerms} in the URL Tag above. This will be replaced with whatever is entered in the searchbox. So if you entered "test", the url will be http://www.google.co.in/search?hl=en&q=test and will take you to that page.Using this as a template, you could modify any REST-ful GET URLs that will retrieve your page. Heck, it would be nice if all webapps have this behaviour as we are all used to entering things in the Search URLs rather than a few clicks.

Deploying this in Browsers:


Firefox (Only 2 and above):
  • Create a HTML File with this tag in the HEAD section of the file
        <link rel="search" type="application/opensearchdescription+xml" title="Some identifiable text" href="/plugin.xml" />
  • In the above example, replace the title with what you want to see in the Search Engine box and href with path to your Opensearch XML File. In my case, its in the DocumentRoot, so the /plugin.xml.
  • Load the html file in your system.
  • Once the page is loaded, you should see a "Add <title>" in the Search engines list.
  • Click on the Button and you should have that plugin added right into your browser.
  • Make that your default section by going to "Manage Search Engines" or just select it to enter text in there which will take you to google
  • If you need to delete this,go to "Manage search engine" and Remove it

Internet Explorer 7:
  • Load the plugin.html directly in your browser
  • In the Search List, click on the button that says "Add Search Providers" and click on the one that you just added
  • Once its done, the plugin should be added in your search list
  • Make that your default or select it to enter search terms
  • As in Firefox, to delete it, go to "Manage engines" and delete it

Note: I wasnt able to get this working on a Firefox 1.0 browser with the above steps. But it looks like the file is located in your system at <Home Directory>/.mozilla/firefox/<encrypted profile dir>/searchplugins directory. I need to check if just copying the plugin.xml into this directory and a subsequent restart will have the same effect. I will confirm this.There are other interesting things you can do with this. You can add an image to the searchbar by adding a "Image" tag with the contents of the image base64 encoded. Also for Mozilla based browsers, there is a Suggestion URL that can be used to retrieve the list of possible suggestions as you start typing. This should be a cool one to do and I will post a tutorial for that.

No comments:

Post a Comment