This is one of those things onto which I’ve been really slow to catch, but which seems to have eluded many other developers so far, so I don’t see sharing it being a waste of time. I eventually decided to look into it this evening and found it’s just as simple to implement as I’d hoped.

I’m talking about allowing browsers to ‘discover’ the search functionality on a site so that users can add it in a couple of clicks to the list of search engines available in the browser’s built-in search box (to the right of the address bar in Firefox, Internet Explorer 7+, etc).

This can be achieved by describing your search engine with an XML file called an OpenSearch description document and providing browsers with a link to that XML in the head of your HTML:

<link rel="search" type="application/opensearchdescription+xml"
    href="/search.xml" title="Example.com Search" />

The specification is described in meticulous detail on the OpenSearch site but the examples of the XML description documents are breezily self-explanatory.

Just be aware that if, like me, you can’t be bothered to return results in RSS or Atom and would rather use your site’s existing old-school get query URLs, you probably want to use the following sort of Url element (instead of the fancy-pants RSS one in the “simple” example):

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>Example.com Search</ShortName>
    <Url type="text/html" method="get"
        template="http://www.example.com/search?q={searchTerms}" />
    <!-- ...snip... -->
</OpenSearchDescription>