Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

OpenSearch providers

Although at first I decided against installing Internet Explorer 7 Beta 2 Preview, I later changed my mind, mainly because I wanted to test this one new feature – (Open)Search Discovery.

Finding (relevant) information on the internet quickly is becoming a serious issue these days, and the quality of search results is crucial for the web search engines to be competitive. Everyone has his or her favorite web search engine and not all search engines return the same results to the same query. And how about specialized search engines, like forums, newsgroups or blogs search engine, a company CMS search engine? Ability to quickly switch among such search engines and narrow your search scope in the very root might just yield that exact results you were after.

IE7 introduced such switching by including OpenSearch support. OpenSearch is a collection of Xml files, some of which extend existing Xml formats, allowing OpenSearch clients to query any OpenSearch-compatible search engine and display the results. So... how does this work?

AutoDiscovery

When you navigate to a web page, which advertises one or more OpenSearch providers, the color of the search box in browser's top-right corner changes from blue to orange, alerting user that there are new search providers available.


Picture 1: Highlighted drop down arrow

Clicking on a down arrow opens up a menu, which informs you of discovered search providers. You can easily select and/or add these providers to your favorite search providers, select default provider, etc.


Picture 2: Drop down menu with Search options


Picture 3: Adding discovered search provider and making it a default one

After adding selected search provider, it is installed in your browser and ready for your queries… It’s really that simple.


Picture 4: Using new default search provider

How does it work?

The trick is in the OpenSearch description file: first, write a simple Xml file, describing how to use your search engine:

<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>Anthology search</ShortName>
  <Description>Search through Anthology</Description>
  <Tags>Anthology CMF</Tags>
  <Contact>info@anthology.si</Contact>
  <Url type="application/rss+xml" 
       template="
http://www.anthology-on.net/
       opensearch.ashx?q={searchTerms}&amp;p={startPage}" />
  <LongName>Anthology search provider</LongName>
</OpenSearchDescription>

Save this file in your web site folder and make it discoverable by putting the following line in the <head></head> section of your main web page and you're done:

<link type="application/opensearchdescription+xml" rel="search" href="opensearch-description.xml">

Writing your own search provider

Look at the Url tag in the above OpenSearch description file. There is a template attribute, which points to your search engine Url address and contains some parameters, which are substituted with actual values before the client calls the search engine. These parameters include:

  • searchTerms: actual text user inputs as a search query,
  • count: number of search results to return,
  • startPage: if count defines the number on one page, this is the number of the page to retrieve (e.g., count=10, startPage=3 : returns search results numbered from 31 to 40). 

Your search engine should of course handle these input values as expected, and, after done processing the query, return the results in the OpenSearch Response formatted file. The OpenSearch Response format is an extension of RSS 2.0 or Atom 1.0 syndication formats, so if you already have some means to generate RSS or Atom files, a few modifications to that file will make your feeds OpenSearch compatible. This is an example of such modification:

<rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">
<channel>
  <title>Search Results</title> 
  <link>http://www.anthology-on.net</link> 
  <description>OpenSearch Anthology Sample</description> 
  <openSearch:startIndex>1</openSearch:startIndex> 
  <openSearch:itemsPerPage>50</openSearch:itemsPerPage> 
  <openSearch:totalResults>272</openSearch:totalResults> 
  <generator>Anthology CMF</generator> 
  <lastBuildDate>Sat, 11 Feb 2006 17:48:26 GMT</lastBuildDate> 
  <item>

...

OpenSearch Homepage offers current OpenSearch specifications, along with additional tips and samples on how to work on its implementation.

Anthology search provider, used in the above example, plays a significant part in the Anthology CMF by allowing third-party search engines to access its documents by using standardized search and aggregating mechanisms. This is the first time I’m mentioning Anthology in this blog: I’ll start writing a series of articles on it soon, so stay tuned! That said – the Url address of Anthology search provider, used in the example, is for demonstration purposes only – it doesn't point to a valid address.