Extend the Searchbar with OpenSearch
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:
<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:
<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/ opensearch/1.1/">
<ShortName>Your website’s title</ShortName>
<Description>A short description of the search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image height="16" width="16" type="image/x-icon"> http://yourdomain.com/favicon.ico</Image>
<Url type="text/html" template="http://yourdomain.com/ search/ ?q={searchTerms}"/>
</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
- OpenSearch documentation (Mozilla Developer Center)
- JSON type-ahead suggestion functionality for OpenSearch
Update: Internet Explorer 8 now supports type ahead suggestions, too.