The A9 search engine (http://a9.com
) created the OpenSearch protocol (http://www.?opensearch.org/?Home
) as a “collection of simple formats for the sharing of search results.”
Many web sites have their own search boxes; many are also capable of creating RSS and Atom feeds. OpenSearch is a set of extensions that can wrap existing search functionality, leveraging the feeds to create lightweight search APIs. The most prominent clients for OpenSearch are the search plug-ins for Firefox 2 and Internet Explorer 7.
Let’s get more concrete. One of the easiest ways to learn how to create a search plug-in is to use the search plug-in generator at the Mozilla Mycroft project (http://mycroft.mozdev.org/?
su
bmitos.html
).
Here I use http://blog.mashupguide.net
as an example site for which I want to generate a search plug-in. I go to the blog to type in a term (for example, Yahoo) to search on and see what URLs come back:
http://blog.mashupguide.net/?s=Yahoo&searchsubmit=Find
I can then replace Yahoo
with {searchTerms}
to generate the search URL for the plug-in generator:
http://blog.mashupguide.net/?s={searchTerms}&searchsubmit=Find
You are given the option to register your search plug-in. One of the great features of the search plug-in wizard is its generation of OpenSearch documents. Here’s the one for the Mashupguide.net plug-in (http://mycroft.mozdev.org/installos.php/?17890/orangeremix.xml
):
<?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/"> <!-- Created on Sun, 17 Jun 2007 17:08:21 GMT --> <ShortName>MashupGuide.net</ShortName> <Description>Search for info about mashups</Description> <Url type="text/html" method="get" template="http://blog.mashupguide.net/?s={searchTerms}&searchsubmit=Find"/> <Image width="16" height="16"> http://mycroft.mozdev.org/updateos.php/id0/orangeremix.png </Image> <Developer>Raymond Yee</Developer> <InputEncoding>UTF-8</InputEncoding> <moz:SearchForm>http://blog.mashupguide.net/</moz:SearchForm> <moz:UpdateUrl> http://mycroft.mozdev.org/updateos.php/id0/orangeremix.xml </moz:UpdateUrl> <moz:IconUpdateUrl> http://mycroft.mozdev.org/updateos.php/id0/orangeremix.png </moz:IconUpdateUrl> <moz:UpdateInterval>7</moz:UpdateInterval> </OpenSearchDescription>
With the OpenSearch XML document in hand, you can then embed some JavaScript to let a user install the plug-in. The relevant method is window.external.AddSearchProvider()
, which you find documented here:
http://msdn2.microsoft.com/en-us/library/Aa744112.aspx
(for Internet Explorer 7)
http://developer.mozilla.org/en/docs/Adding_search_engines_from_web_pages
(for Firefox)
You can get a list of search engine plug-ins here:
https://addons.mozilla.org/en-US/firefox/browse/type:4
(a popular list linked to from within the Firefox Manage Search Engine List widget)
http://mycroft.mozdev.org/dlstats.html
(the top downloads)
Note a caveat from http://mycroft.mozdev.org/contribute.html
:
While the implementation of Sherlock [the legacy Apple search tool] in Mozilla-based browsers only supported GET requests, the introduction of OpenSearch has also allowed POST requests to be used but unfortunately this is not currently supported in IE7.
You can use the following WordPress plug-in to generate a search plug-in:
http://inner.geek.nz/projects/wordpress-plugins/mycroft-search-plugin-generator/
There is another half to the OpenSearch specification. If the search results that come out of the search engine are in RSS 2.0 or Atom 1.0 format, wrapped with special elements documented here:
http://www.opensearch.org/Specifications/OpenSearch/1.1#OpenSearch_response_elements
then the search results can be consumed and presented by search clients that support the OpenSearch protocol:
http://www.opensearch.org/Community/OpenSearch_search_clients
and by programming libraries that can use it:
http://www.opensearch.org/Community/OpenSearch_software
In other words, you can get lightweight APIs for these sources and build metasearch systems from them. In the specific case of WordPress search results, you can make WordPress into a full OpenSearch source using a WordPress plug-in, such as the following: