OpenSearch in IE7 and Firefox2

November 05, 2006

opensearch in FF2Over the past few weeks both Firefox 2 and IE7 have been released, both excellent updates and both offering a new feature with regard to searching. Search Plugins, (something which has been in previous FF versions but in a less accessible way) are a way of adding new searches to your search list so that you can access them just by selecting it in your menu and then querying.

The cool thing however is that this supports auto-discovery meaning if your site has the right bits of code included visitors to your site will be able to add your “search plugin” in just a few clicks. You can see an example of this in the image to the right.

So how you do add this functionality to your site? Well… quite easily as it happens.

The XML

The first thing you need is an XML file, I’ve called mine search.xml and it’s in this file that we will do all of the configuration for the search. Here’s what mine looks like:

  <?xml version="1.0" encoding="UTF-8"?>
   <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
     <ShortName>SimpleByDesign.org.uk</ShortName>
     <Description>Quickly Search Entries on Simple By Design</Description>
   
     <AdultContent>false</AdultContent>
     <Url template="http://creativeflux.co.uk/search/?query={searchTerms}&amp;amp;amp;section=entries&amp;amp;amp;limit=50&amp;amp;amp;search-mode=simple" type="text/html"></Url>
     <OutputEncoding>UTF-8</OutputEncoding>
     <InputEncoding>UTF-8</InputEncoding>
   </OpenSearchDescription>
  • The first part is just adding the Open Search namespace
  • Shortname Lets us give our search a name
  • Description is pretty self explanatory
  • Adult Content once again, self-explanatory
  • Input/Output Encoding this is just specifying the encoding your site requires for input and the encoding it will use for output.

I’ve deliberately left the URL bit for last since it’s the only semi-tricky part. A good way to get your search URL is to do a search on your site and if you use GET like I do you will get a long URL and somewhere in it there will be the query you searched for. Copy that link into your XML file and where you find your query replace it with:

{searchTerms}

Also if there are any ampersands in your URL then be sure to “encode” them correctly like this – amp;

Now your XML file is done you need to upload it your webserver. I just dropped mine in my sites root.

Editing your Page(s)

This bit is easy. First you need to add the add a profile attribute to your head tag like so:

<head profile="http://a9.com/-/spec/opensearch/1.1/"></head>

and then finally you need add this somewhere in your header:

<link href="http://link-to-your-xml-file.xml" title="SimpleByDesign.org.uk" rel="search" type="application/opensearchdescription+xml" />

And now you should be able to browse to your site in IE7 or Firefox 2 and add your search from the drop down menu.

That’s all there is too it, happy searching!

Feedback?

If you’ve found errors or have some feedback please . Comments aren’t currently enabled due to spam but I’m sure they’ll return in the future.

More Reading

Previously: Symphony Section Search

Coming Up: New Mixed Wallpaper Pack