Add OpenSearch search to your site

One of the original reasons I switched to Firefox was the built-in Google search box. Now even Internet Explorer has built in search. You can search Google, Bing, Wikipedia, etc, but what if you want people to be able to search your site from their browser? What if you want to search some other site from your browser?

Enter OpenSearch. OpenSearch describes a format for a special XML file you host on your site. When an OpenSearch compatible client comes along, they can detect that file and allow the user to search using the parameters you specify. Basically, it’s a way to let Firefox, IE, and other browser users to search your site from their built in search box.

The OpenSearch website has the nitty gritty details, but here’s my OpenSearch file (customsearch.xml):

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Stuporglue.org</ShortName>
 <Description>Search Stuporglue.org</Description>
 <InputEncoding>UTF-8</InputEncoding>
 <Image width="16" height="16" type="image/x-icon">http://stuporglue.org/favicon.ico</Image>
 <Url type="text/html" method="GET" template="http://stuporglue.org/?s={searchTerms}"></Url>
 <moz:SearchForm>http://www.stuporglue.org/search/</moz:SearchForm>
</OpenSearchDescription>

The key part is the Url with the {searchTerms} parameter. Whatever the user searches for in the search box will be put into that part of the query string.

To make your custom search file auto-detectable, we need to add a line to the <head> section of our HTML.

<link rel="search" type="application/opensearchdescription+xml" title="Stuporglue.org" href="/wp-supplements/customsearch.xml">

How this will present itself to the user will depend on their browser. In Firefox the search engine chooser drop-down arrow glows. In IE, it turns green.

Is this a killer feature for all websites? No. But it does have its uses. At a company I used to work for, I had to search internal documentation several times a day. When I got tired of navigating to the search page again and again, I created an OpenSearch file, added the internal search to my Firefox and was more efficient from that day on.

This entry was posted in Programming, Projects and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *