mozilla

Revision 162446 of Creating MozSearch plugins

  • Revision slug: Creating_MozSearch_plugins
  • Revision title: Creating MozSearch plugins
  • Revision id: 162446
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment /* The plugin file */

Revision Content

Firefox 2.0 supports Amazon A9's OpenSearch format for creating search plugins.

A search plugin is an XML file that describes the search engine, its URL, and the parameters that need to be passed to that URL.

The plugin file

The XML file describing a search engine is actually quite simple, following the basic template below. Sections in italics need to be customized based on the needs of the specific search engine plugin you're writing.

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>engineName</ShortName>
<Description>engineDescription</Description>
<InputEncoding>inputEncoding</InputEncoding>
<SuggestionURL>suggestionUrl</SuggestionURL>
<Image width="16" height="16">data:image/x-icon;base64,imageData</image>
<Url type="text/plain" method="method" template="searchURL">
  <Param name="paramName1" value="paramName1"/>
  ...
  <Param name="paramNameN" value="paramValueN"/>
</Url>
<SearchForm>searchFormURL</SearchForm> 
</SearchPlugin>
engineName
A short name for the search engine.
engineDescription
A brief description of the search engine.
inputEncoding
The encoding to use for the data input to the search engine.
suggestionUrl
If the search engine supports making find-as-you-type suggestions, this URL is used to do lookups based on the current content of the search box while typing to provide a drop-down menu listing the returned search results.

Image:SearchSuggestionSample.png

imageData
Base-64 encoded 16x16 icon representative of the search engine.
method
The method to use for sending the search query: GET or POST.
searchURL
The base URL for the search query. The parameters described inside the <Url> element are appended to this URL.
paramName1 ... paramNameN
The names of each parameter that need to be passed in along with the search query.
paramValue1 ... paramValueN
The values for each of the parameters passed along with the search query. You can use {searchTerms} to insert the search terms entered by the user in the search box.
searchFormURL
The URL to go to to open up the search page at the site for which the plugin is designed to search. This provides a way for Firefox to let the user visit the web site directly.

An example: searching Yahoo!

The following XML is the Firefox 2 search plugin for searching using Yahoo!:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Yahoo</ShortName>
<Description>Yahoo Search</Description>
<InputEncoding>UTF-8</InputEncoding>
<SuggestionURL>http://ff.search.yahoo.com/gossip?output=fxjson&command=</SuggestionURL>
<Image width="16" height="16">data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==</Image>
<Url type="text/html" method="GET" template="http://search.yahoo.com/search">
  <Param name="p" value="{searchTerms}"/>
  <Param name="ei" value="UTF-8"/>
  <Param name="fr" value="moz2"/>
</Url>
<SearchForm>http://search.yahoo.com/</SearchForm>
</SearchPlugin>

Revision Source

<p>Firefox 2.0 supports Amazon A9's <a class="external" href="http://opensearch.a9.com/">OpenSearch</a> format for creating search plugins.
</p><p>A search plugin is an XML file that describes the search engine, its URL, and the parameters that need to be passed to that URL.
</p>
<h2 name="The_plugin_file">The plugin file</h2>
<p>The XML file describing a search engine is actually quite simple, following the basic template below.  Sections in italics need to be customized based on the needs of the specific search engine plugin you're writing.
</p>
<pre class="eval">&lt;SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/"&gt;
&lt;ShortName&gt;<i>engineName</i>&lt;/ShortName&gt;
&lt;Description&gt;<i>engineDescription</i>&lt;/Description&gt;
&lt;InputEncoding&gt;<i>inputEncoding</i>&lt;/InputEncoding&gt;
&lt;SuggestionURL&gt;<i>suggestionUrl</i>&lt;/SuggestionURL&gt;
&lt;Image width="16" height="16"&gt;data:image/x-icon;base64,<i>imageData</i>&lt;/image&gt;
&lt;Url type="text/plain" method="<i>method</i>" template="<i>searchURL</i>"&gt;
  &lt;Param name="<i>paramName1</i>" value="paramName1"/&gt;
  ...
  &lt;Param name="<i>paramNameN</i>" value="<i>paramValueN</i>"/&gt;
&lt;/Url&gt;
&lt;SearchForm&gt;<i>searchFormURL</i>&lt;/SearchForm&gt; 
&lt;/SearchPlugin&gt;
</pre>
<dl><dt> <b>engineName</b>
</dt><dd> A short name for the search engine.
</dd></dl>
<dl><dt> <b>engineDescription</b>
</dt><dd> A brief description of the search engine.
</dd></dl>
<dl><dt> <b>inputEncoding</b>
</dt><dd> The encoding to use for the data input to the search engine.
</dd></dl>
<dl><dt> <b>suggestionUrl</b>
</dt><dd> If the search engine supports making find-as-you-type suggestions, this URL is used to do lookups based on the current content of the search box while typing to provide a drop-down menu listing the returned search results.
</dd></dl>
<p><img alt="Image:SearchSuggestionSample.png" src="File:en/Media_Gallery/SearchSuggestionSample.png">
</p>
<dl><dt> <b>imageData</b>
</dt><dd> Base-64 encoded 16x16 icon representative of the search engine.
</dd></dl>
<dl><dt> <b>method</b>
</dt><dd> The method to use for sending the search query: <code>GET</code> or <code>POST</code>.
</dd></dl>
<dl><dt> <b>searchURL</b>
</dt><dd> The base URL for the search query.  The parameters described inside the <code>&lt;Url&gt;</code> element are appended to this URL.
</dd></dl>
<dl><dt> <b>paramName1</b> ... <b>paramNameN</b>
</dt><dd> The names of each parameter that need to be passed in along with the search query.
</dd></dl>
<dl><dt> <b>paramValue1</b> ... <b>paramValueN</b>
</dt><dd> The values for each of the parameters passed along with the search query.  You can use <code>{searchTerms}</code> to insert the search terms entered by the user in the search box.
</dd></dl>
<dl><dt> <b>searchFormURL</b>
</dt><dd> The URL to go to to open up the search page at the site for which the plugin is designed to search.  This provides a way for Firefox to let the user visit the web site directly.
</dd></dl>
<h2 name="An_example:_searching_Yahoo.21">An example: searching Yahoo!</h2>
<p>The following XML is the Firefox 2 search plugin for searching using Yahoo!:
</p>
<pre>&lt;SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/"&gt;
&lt;ShortName&gt;Yahoo&lt;/ShortName&gt;
&lt;Description&gt;Yahoo Search&lt;/Description&gt;
&lt;InputEncoding&gt;UTF-8&lt;/InputEncoding&gt;
&lt;SuggestionURL&gt;http://ff.search.yahoo.com/gossip?output=fxjson&amp;command=&lt;/SuggestionURL&gt;
&lt;Image width="16" height="16"&gt;data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==&lt;/Image&gt;
&lt;Url type="text/html" method="GET" template="http://search.yahoo.com/search"&gt;
  &lt;Param name="p" value="{searchTerms}"/&gt;
  &lt;Param name="ei" value="UTF-8"/&gt;
  &lt;Param name="fr" value="moz2"/&gt;
&lt;/Url&gt;
&lt;SearchForm&gt;http://search.yahoo.com/&lt;/SearchForm&gt;
&lt;/SearchPlugin&gt;
</pre>
Revert to this revision