Extend the Searchbar with OpenSearch

Screenshot of the searchbar in Firefox with the option "Add Wikipedia (English)" OpenSearch is known as an open source format to syndicate and aggregate search results. It was developed by Amazon / A9 and quickly gained support from the big search engines. Their involvement is somewhat intimidating — your site’s not Google, so who wants to syndicate your search results anyway?

But if your blog or a client has a loyal readership, it would be convenient if they could just use their browser’s searchbar as a shortcut. For example currently we work on a website relaunch for a big German city, and it’s easily conceivable that citizens want to search this site more often.

Here comes a side effect of OpenSearch: the OpenSearch descriptions are machine readable XML files. Firefox and Internet Explorer 7 are two of those “machines” if you let them know the file exists:

  1. <link rel="search" type="application/ opensearchdescription+xml" title="Your website’s title" href="/opensearch.xml" />

Of course that belongs in the head. Now all you need are a few more lines of code in the opensearch.xml file:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <OpenSearchDescription xmlns="http://a9.com/-/spec/ opensearch/1.1/">
  3. <ShortName>Your website’s title</ShortName>
  4. <Description>A short description of the search</Description>
  5. <InputEncoding>UTF-8</InputEncoding>
  6. <Image height="16" width="16" type="image/x-icon"> http://yourdomain.com/favicon.ico</Image>
  7. <Url type="text/html" template="http://yourdomain.com/ search/ ?q={searchTerms}"/>
  8. </OpenSearchDescription>

Just change the shortname property, the favorite icon path, the search URI and parameters. Don’t change {searchTerms}. And that’s all, it’s a five minute no-brainer…

Further Reading

Update: Internet Explorer 8 now supports type ahead suggestions, too.

Comments are closed.