Add OpenSearch to your web site

Chris Wilson, the main guy behind IE7 (and older versions) discussed several new features of Internet Explorer 7 at the @media conference in London. One feature in particular that stood out for me was the OpenSearch protocol. Adding this to your site can be easy, it can also be a headache.

What is OpenSearch?

OpenSearch was developed by Amazon’s A9 search engine to enable aggregators to easily acquire content and make more robust search result pages. Internet Explorer 7 is using this protocol to give users the ability to search a site via the integrated search box.  It’s a two step process: create an XML document that defines your site’s search engine methods and then place a link to that XML in your page header. It sounds simple enough lets see it in action and then learn how to build the XML document.

Using OpenSearch

Yahoo! Tech recently added OpenSearch. If you have Internet Explorer 7 on your computer, you can enjoy the OpenSearch experience right away.  If you don’t have IE7 yet, download it now!

Yahoo! Tech and OpenSearch
Internet Explorer 7 has a built in search box in the top right of the page. If you have added OpenSearch to your site you will notice the box has an orange down arrow. Clicking on this arrow will expose a new menu. You can now search this site via the box and add the site to your favorite search engines.

If your site offers search results in RSS or Atom format, you’ll get enhanced functionality in your search results. Yahoo! Tech only features HTML results, so we give you the option of using the built in search box. 

At this point you may be saying… Is that all there is?  Well, yes. With a little bit of work, you are giving your visitors the ability to search from the built in search box and you are making it easier for A9 and other search engines to spider your content and surface your site in their results.  Let’s look at how easy it is to implement.

The OpenSearch XML

The XML document is fairly simple, you define the site’s name, description, attributions, favicon, and other simple elements. The important element is the Url.  This is where you define the location of your search engine and the parameter passed to define the query.

On Yahoo! Tech, the search page is tech.yahoo.com/sp and the query is passed as prod=search+term.  The OpenSearch XML expects you to use this specific markup {searchTerms} where you want the engine or IE7 search box to insert the query terms. Further, I found it much easier to write the url as a whole string, rather than setting the prod parameter as a sub-element. You can also allow the search engines to narrow the results by number {count} and more.

Let’s look at the XML in depth.




Start off the xml file with the standard opening. We then open the OpenSearchDescription element. There is a link to a9.com to define the namespace.


Yahoo! Tech
Search for the best gadgets and how to use your tech gear on Yahoo! Tech
tech gadgets technology cameras phones shopping

Define a short name for your site. Give it a description and the tags that define your site.





Yahoo! Tech is only providing an HTML version of the search results; you can visit the search result page. If we provided an RSS version the type would be application/rss+xml. The template is the location of the final search page. Notice how the searchTerms variable is inline. Ideally, I could have left ?prod=… out of the url and defined it as a parameter, but this caused inconsistent implementation.

We then define another parameter, the results and the value is the OpenSearch variable for the number of results returned. You can see a full list of parameters on the A9 OpenSearch web site.


Yahoo! Tech Search
Yahoo! Tech
Copyright © 2006 Yahoo! Inc. All rights reserved.
http://www.yahoo.com/favicon.ico

We are now providing a longer name where it is appropriate to display it. The developer is Yahoo! Tech. The attribution is how we want results credited. We are using  the standard copyright information. We also define  the location of our favicon. You can define multiple icons for inside the box and if you have RSS, on the results page.



open
false
en-us
UTF-8
UTF-8

Finally, we add some extra information about the display, search content, and close the XML. Overall, it’s a fairly small, simple bit of XML(tech-opensearch.xml).  There’s a full list of parameters you can add to your search query and elements to define your xml at: http://opensearch.a9.com/spec/1.1/

Do you want to make it even easier?

Go over to Enhance IE and use their simple OpenSearch generator to build the XML for you! Simply do a search for TEST on your site and copy that url into their form. Voila, you’ve got a basic OpenSearch XML file.

Activating your OpenSearch XML

If you provide an RSS or Atom feed, you can log in to A9 and register your site. Internet Explorer 7 also needs to know where your XML document is located as well.  Simply add a link to it in the head of your document:

While Chris was busy hyping the latest features of Internet Explorer 7, the OpenSearch protocol will also be supported by Firefox 2.0. That’s two for the price of one!.

WordPress and OpenSearch

If it’s so easy, why doesn’t it work on this blog? WordPress blogs are setup to use the index page as the search page.  This is the results page for a search of XML on this blog: http://last-child.com/index.php?s=xml

I’ve tried setting up the XML to point towards index.php and get the subsequent errors.  Chris Fairbanks has released an OpenSearch plugin for WordPress (http://www.williamsburger.com/wb/archives/opensearch-v-1-0).  It’s not a simple procedure and I simply haven’t had time to implement it.

With the introduction of Microformats and the OpenSearch protocol, the (lowercase!) semantic web is getting closer to being a reality. This bit of xml is fairly easy to generate and opens your site to new audiences and functionality. Spend an hour or two getting acquainted with the OpenSearch concept and activate your site today.

Related Information

How to rebuild a site with standards – ala iconfactory

The folks behind iconfactory.com are undergoing a massive reconstruction of their site. They’ve taken it off-line as they tear out the old ASP backend, table-based layouts and tons of br tags.

How do I know this? I watched their cartoons. They’ve created a clever set of movies to illustrate the process of tearing apart an outdated site and building it back up with the latest techniques. I particularly like the frustration of getting huge amounts of errors on a W3C validation test.

Warning: You need to have Quicktime installed. But then, who doesn’t have iTunes on their computer by now.

Microformats and Yahoo! Tech

You’ve probably heard of Microformats by now. It’s that vague concept floated amongst the standardistas which promises to solve world hunger and bring peace to the Middle East. You’ve always got something more immediate to do and hope to read about it soon. Heck, you don’t even know how it is actually used as an end product. Isn’t it just more code in the page?

All of these questions and issues kept me from trying out microformats until Tantek Çelik  gave a lecture at Yahoo! this year.  While the usefulness of the concept was still vague, the ease of implementation inspired us to give it a try.

Microformats let you define information in your page with a set of recognized classes. A parser (program or web site that transforms your information into useful tools) looks for containers with those classes and collects the information within them.  The user is then able to add people, events, recipes, web sites, etc to their organizers, databases, etc. Think of it as a way to multi-task your web pages.

Yahoo! Tech launched with basic support of the hReview microformat. We’ve continued to investigate how we can further support microformats and similar technology.

Introducing the Yahoo! Tech Bloggers with hCard microformat

The hCard microformat is based on a pre-existing standard (vCard).  There are many programs, web sites, and aggregators that are already prepared to use your information. You can add this to your site quite easily.

hcard microformat details on Yahoo! Tech

Let’s look at some code on a blog post by Robin Raskin (http://tech.yahoo.com/blogs/raskin/621) This block begins with a list of content for the microformat parser, since it is not a part of the visual design, we are hiding it with CSS. The next section includes a set of links, her bio link has class=”url”.


 

Microformat classes and their functions

  • div.vcard: This triggers the parser, letting it know the following information conforms to the hCard microformat
  • li.fn: This is the formatted name of the person: Robin Raskin.
  • li.title: Robin Raskin’s title – Yahoo! Tech Advisor
  • li.org: The company Robin works for – Yahoo! Tech
  • img.photo: This is a photograph of Robin
  • a.url: This is a web site for Robin.
  • a.url.email: If the Email Robin link were in the classic mailto:foo@foo.com format, we’d use these classes. Instead, the target is a contact form. To avoid confusion, we’ve left this link alone.

Testing your microformatting

Tails is a great Firefox extension for testing your code. It will display an icon in the browser if a page has microformatting. You can then click on it to open a window with all of the available information. This is a great debugging tool. Be sure to get the latest version for the best microformats support and extensibility.

An intertwining pattern library

Microformats are a rapidly growing technology. As patterns develop, they can be integrated into various other microformats and patterns. This requires going beneath the surface of the microformat twiki to harness its power.  While your results may not bring immediate benefits, the level of work can be minimal. This also requires having some faith in your code, as you may not be able to test the results.

The rel-tag microformat

Technorati has made the rel-tag an important addition to web sites. Simply add rel=”tag” to a link that refers to a page that is an index for information about the link text.  For instance, Robin Raskin’s page features a set of category related links. The rel-tag microformat lets Technorati and other parsers know where to will find the category index pages. 

The rel-directory pattern extends this concept. If Robin’s post was about digital cameras and she included a link to the digital camera index, we could add “directory” to the rel tag.  The final code would be:


Digital Cameras

The rel-home draft

Ther rel-home draft allows web developers to specifically define the link that takes the user to the home page of the site. Currently this can be done without microformatting; but lacks significant browser support. To use straight HTML, place this in the head of your page: <link rel=”home” href=”/index.html” />. Theoretically, the browser would detect this and give the user a hotkey to go back to the home page.

The rel-home microformat draft allows the developer to easily label the home page link. For instance, on Yahoo! Tech, the user can either click the large Tech logo or the products tab. Neither of these are the most intuitive, the rel-home could provide further assistance. Browsers don’t support this yet, but its simplicity makes it a natural to begin now.
The code is quite simple, add rel=”home” to your link:


Products

Should you begin using Microformats?

As you can see, the code is fairly simple. If your site is already presenting contact information, reviews, calendar events, or category indices, it’s time to look at adding a few Microformat details. The rel-tag, rel-home patterns are the easiest to apply. The hCard and hCalendar formats will give you the most usable information. Keep an eye on microformats.org for the latest developments and join their discussion list to play an active part in the evolution of patterns. Microformats may not bring peace to the Middle East, but they will give your web site’s content more power and functionality.

Resources

YUI libraries are updated again!

The Yahoo! platform developers work continuously to make the YUI libraries as bulletproof as possible. Don’t pass up on this opportunity to have top-quality interactions that scale to enormous traffic, are platform independent, and evolve with new technology and concepts. Remember, they’re built for Yahoo! first and then offered to you for free. They’ve got to be the best to handle Yahoo’s demands.

The libraries are now version v.0.11. I think that still puts them in the pre-teen category. Wait until they hit version .14 when they begin listening to really bad boy bands and hanging out at the mall after school.

Visit the YUI developer blog today to get the lowdown on all of the fixes. I have had an annoying issue with a select box and z-index that will be fixed with the introduction of this latest version. So make sure you update your import links and enjoy.

Here’s a summary of the benefits:

WCAG 2.0 Quick Reference Guide

While speaking at the @media conference this year, Gez Lemon announced an easier way to understanding the new WCAG 2.0 requirements. They are meant to be technology neutral to allow future flexibility. Unfortunately, this also makes them difficult to understand. If you are only concerned about HTML, CSS, XML, or another format, use the WCAG 2.0 Quick Reference Guide to narrow the specifications to only those you are worried about.