Implementing OpenSearch

A relevant ad will be displayed here soon. These ads help pay for my hosting.
Please consider disabling your ad blocker on Pony Foo. These ads help pay for my hosting.
You can support Pony Foo directly through Patreon or via PayPal.

OpenSearch is an specification that allows websites to improve usability. When implemented, it allows consumers to search your site the way you intended them to. All major browsers support OpenSearch. Google Chrome for instance, allows users to search OpenSearch-enabled websites by using tab in the search bar.

The Standard

The first thing you need to do, is compose an XML file that conforms to the OpenSearch standard. I’ll just provide an example of how I implemented it in this blog.

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
    <ShortName>Pony Foo</ShortName>
    <Description>Search Pony Foo: Ramblings of a degenerate coder</Description>
    <Image height="16" width="16" type="image/x-icon">http://blog.ponyfoo.com/favicon.ico</Image>
    <Url type="text/html" method="get" template="http://blog.ponyfoo.com/search/{searchTerms}" />

The {searchTerms} placeholder will be replaced with the user’s query.

Next, all you have to do is reference your OpenSearch file somewhere, and reference it in site home, like this:

<link rel='search' type='application/opensearchdescription+xml' title='Pony Foo' href='/opensearch.xml' />

You can see OpenSearch in action at IMDb.com, StackOverflow, or right here.

Liked the article? Subscribe below to get an email when new articles come out! Also, follow @ponyfoo on Twitter and @ponyfoo on Facebook.
One-click unsubscribe, anytime. Learn more.