Search suggestions in Firefox
May 27th, 2006 by DeWitt Clinton

I notice that the milestone release of Firefox 2 has implemented a mechanism for “Google Suggest“-style auto-completions right in the browser’s search box. Very neat feature.

I haven’t pinged Gavin yet about whether or not this feature will be exposed in the new search plugin model. This document hints that it might be; perhaps via an additional element called <SuggestionsURL/>. Of course, those are early design docs, not formal specifications, so I don’t want to read too much into anything.

And Google/Firefox developer Tony Chang wrote earlier today about a Wikipedia Suggest implementation he cranked out. Tony’s impressively concise “80 lines of Python” lead me to believe that the element might be called <SuggestionURL/> (no “s”) and live in the OpenSearch Description document.

But now that I’m thinking about it, one appropriate way to expose the “suggest” URLs would be by reusing the existing <Url> element in the OpenSearch Description document. The type attribute would indicate that the URL is for a “suggestion” search. The docs recommend returning JSON; this too can be accounted for in the type value.

The type I have in mind is:

application/x-suggestions+json

Thus a full “suggest” URL element would look something like this (using Google’s API as an example):

<Url type="application/x-suggestions+json"
     template="http://www.google.com/complete/search?hl=en&amp;js=true&amp;qu={searchTerms}"/>

A full OpenSearch Description document, with a “x-suggestions” type:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>Web Search</ShortName>
  <Description>Use Example.com to search the Web.</Description>
  <Tags>example web</Tags>
  <Contact>admin@example.com</Contact>
  <Url type="text/html"
     template="http://example.com/html/{searchTerms}&amp;pw={startPage?}"/>
  <Url type="application/atom+xml"
     template="http://example.com/atom/{searchTerms}&amp;pw={startPage?}"/>
  <Url type=”application/x-suggestions+json”
     template=”http://example.com/suggest/{searchTerms}”/>
</OpenSearchDescription>

Clients that support “application/x-suggestions” could thus explicitly look for this type and call the URL accordingly. Also, the “content type+format” notation will help if search engines and clients decide to support “+xml” or similar some time in the future.

Another nice thing about doing it this way is that it reuses the convention of {searchTerms} as a template parameter. The other way simply tacks on the search at the end of the string. This would be a bit more flexible and potentially support more suggestion APIs.

Yet another plus is that this approach doesn’t even require an extension to OpenSearch. Clients that want suggestion URLs will look for it by type; clients that don’t will silently ignore it.

This approach feels right to me, but I’d like to sleep on it.

[Update: Fixed the encoding of the '&' characters in my sample URLs.]

[Update 2: Fixed typos.]

3 Responses to “Search suggestions in Firefox”

  1. Joe Hughes Says:

    I’m glad you like the suggestions feature–I’ve been working on it with Gavin, Mike Connor, and Mike Beltzner over the last few weeks. We’ve stubbed support into the format (see Google and Yahoo! examples) in the interests of getting it out the door for the alphas, so it’s worth revisiting. Your proposal looks a bit more robust than what’s currently there.

    The other thing I’d like to describe in the spec is a parameter on the actual search that indicates that the query terms came from a server suggestion–this would allow the engine to avoid a suggestions feedback loop.

  2. DeWitt Clinton Says:

    This is great, Joe. Thank you. I’ll ping you tomorrow about the details.

    Also, I’m working on an OpenSearch extension that will allow OpenSearch search engines to request a “source” parameter that indicates which search client is requesting the search. The IE guys came up with the idea and I proposed releasing it as a “official” extension so we can all use the same approach.

    I’ve already spoken with Gavin about it, and I think we can use that extension to solve the “feedback loop” issue you raise.

    Cheers,

    -DeWitt

  3. Puzzlepieces – OpenSearch Update (June 11, 2006) Says:

    [...] Firefox’s beta also has support for “search suggestions” when using Google or Yahoo. DeWitt has shown how (see draft document) these suggestions can be implemented in a way that is completely compatible with OpenSearch, without changing the existing format (JSON) at all. And it also opens the door to allowing suggestions themselves in OpenSearch; the Query element is ideal for this purpose. [...]