Supporting search suggestions in search plugins

  • Revision slug: Supporting_search_suggestions_in_search_plugins
  • Revision title: Supporting search suggestions in search plugins
  • Revision id: 182693
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Much more content

Revision Content

MozSearch supports search suggestions; as the user types in the search bar, Firefox 2 queries the URL specified by the search engine plugin's <SuggestionUrl> element to fetch live search suggestions.

Once the list has been retrieved, it's displayed in a popup box that appears under the search bar, which lets the user select a suggested search term. If the user continues to type, a new set of suggestions is requested from the search engine, and the displayed list is refreshed.

The Yahoo and Google search plugins included with Firefox 2 support search suggestions.

Implementing suggestion support in the search plugin

The search plugin specifies the <SuggestionUrl> to query for a list of search suggestions. The search term is appended to this URL, then queried using an HTTP GET request.

For example, the Yahoo search plugin has this <SuggestionUrl>:

<SuggestionUrl>http://ff.search.yahoo.com/gossip?output=fxjson&command=</SuggestionUrl>

If the user types "fir" into the search bar, then pauses, Firefox appends "fir" to the <SuggestionUrl>, then queries that URL:

<SuggestionUrl>http://ff.search.yahoo.com/gossip?output=fxjson&command=fir</SuggestionUrl>

The results are used to construct the suggestion list box.

See Creating MozSearch plugins to learn more about how to implement a search plugin.

Implementing search suggestion support on the server

The majority of the work in handling search suggestions is actually implemented on the server side. If you're a web site designer, and want to support search suggestions, you need to implement support for returning the suggestions in JavaScript Object Notation (JSON) given a search term.

When the browser wants to fetch possible matches for a search term, it appends the search term to the <SuggestionUrl> then sends an HTTP GET request to that URL.

Your server should then decide upon the suggestions to offer using whatever means it sees fit, and construct a JSON result, which is formatted like this:

["search term", [match list]]

search term is the search term that was queried, and the match list is a comma-deliniated, quoted list of suggested terms. For example, if the search term is "fir", you might return the following JSON:

["fir",["firefox","first choice","mozilla firefox"]]

You can return however many suggestions you like, although keeping it to a manageable number is recommended.

Revision Source

<p>MozSearch supports search suggestions; as the user types in the search bar, Firefox 2 queries the URL specified by the search engine plugin's <code>&lt;SuggestionUrl&gt;</code> element to fetch live search suggestions.
</p><p>Once the list has been retrieved, it's displayed in a popup box that appears under the search bar, which lets the user select a suggested search term.  If the user continues to type, a new set of suggestions is requested from the search engine, and the displayed list is refreshed.
</p><p>The Yahoo and Google search plugins included with Firefox 2 support search suggestions.
</p>
<h2 name="Implementing_suggestion_support_in_the_search_plugin">Implementing suggestion support in the search plugin</h2>
<p>The search plugin specifies the <code>&lt;SuggestionUrl&gt;</code> to query for a list of search suggestions.  The search term is appended to this URL, then queried using an HTTP <code>GET</code> request.
</p><p>For example, the Yahoo search plugin has this <code>&lt;SuggestionUrl&gt;</code>:
</p>
<pre>&lt;SuggestionUrl&gt;http://ff.search.yahoo.com/gossip?output=fxjson&amp;command=&lt;/SuggestionUrl&gt;
</pre>
<p>If the user types "fir" into the search bar, then pauses, Firefox appends "fir" to the <code>&lt;SuggestionUrl&gt;</code>, then queries that URL:
</p>
<pre>&lt;SuggestionUrl&gt;http://ff.search.yahoo.com/gossip?output=fxjson&amp;command=fir&lt;/SuggestionUrl&gt;
</pre>
<p>The results are used to construct the suggestion list box.
</p><p>See <a href="en/Creating_MozSearch_plugins">Creating MozSearch plugins</a> to learn more about how to implement a search plugin.
</p>
<h2 name="Implementing_search_suggestion_support_on_the_server">Implementing search suggestion support on the server</h2>
<p>The majority of the work in handling search suggestions is actually implemented on the server side.  If you're a web site designer, and want to support search suggestions, you need to implement support for returning the suggestions in JavaScript Object Notation (JSON) given a search term.
</p><p>When the browser wants to fetch possible matches for a search term, it appends the search term to the <code>&lt;SuggestionUrl&gt;</code> then sends an HTTP <code>GET</code> request to that URL.
</p><p>Your server should then decide upon the suggestions to offer using whatever means it sees fit, and construct a JSON result, which is formatted like this:
</p>
<pre class="eval">["<i>search term</i>", [<i>match list</i>]]
</pre>
<p><i>search term</i> is the search term that was queried, and the <i>match list</i> is a comma-deliniated, quoted list of suggested terms.  For example, if the search term is "fir", you might return the following JSON:
</p>
<pre class="eval">["fir",["firefox","first choice","mozilla firefox"]]
</pre>
<p>You can return however many suggestions you like, although keeping it to a manageable number is recommended.
</p>
Revert to this revision