Add OpenSearch search to your site

Posted by stuporglue on Mar 18, 2010 in Programming, Projects
Subscribe to posts by category...
Programming, Projects

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.

Tell Your Friends
  • Digg
  • Facebook
  • Google Bookmarks
  • RSS
  • StumbleUpon
  • Twitter

Tags:

Leave a Reply

XHTML: You can use these tags:' <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Original content on this page is under the Creative Commons Attribution-ShareAlike 3.0 License unless otherwise noted.

If you found this page particularly helpful, I'd love to hear from you. A link to this page from your blog or website would also be appreciated.

I'm the real Michael Moore