Mar 19, 2009
[Misc] OpenSearch に対応する方法
OpenSearch とは
OpenSearch.org によると、OpenSearch とは
OpenSearch is a collection of simple formats for the sharing of search results.というものらしい。 対応すると Firefox の検索バーに Google や Yahoo と並んで自分のサイトを表示できる様だ。 早速遊んでみることに。
You can use OpenSearch formats to help people discover and use your search engine and to syndicate search results across the web.
- OpenSearch.org
- http://www.opensearch.org/Home
- Creating OpenSearch plugins for Firefox
- https://developer.mozilla.org/ja/Creating_OpenSearch_plugins_for_Firefox
OpenSearch description document の作成
まずは OpenSearch description document を作成する。 詳細は OpenSearch description document に譲ることにして、ここではこのブログ用の内容をメモしておく。
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>in-vitro.jp blog search</ShortName>
<Description>in-vitro.jp blog search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAPSGlDQ1BJQ0...(略)</Image>
<Url type="text/html" method="GET" template="http://www.in-vitro.jp/blog/google.cgi">
<Param name="key" value="site:www.in-vitro.jp/blog/"/>
<Param name="q" value="{searchTerms}"/>
</Url>
<moz:SearchForm>http://www.in-vitro.jp/blog/</moz:SearchForm>
</OpenSearchDescription>
以下の 2 点だけ気をつければ作成自体は特に難しいことではない。
- 検索のクエリ文字列は {searchTerms} で置換される。
- アイコン 16 x 16 で作成し、Base64 でエンコードして <Image> 内に埋め込む。サーバに置いて参照することもできる様だ(上の例では埋め込んでいる)。アイコンを Base64 でエンコードするのは The data: URI kitchen を使うと楽。
HTML ヘッダにリンクを設定
HTML ヘッダに OpenSearch description document へのリンクを設定する。
<html>
<head>
...
<link rel="search" type="application/opensearchdescription+xml" title="in-vitro.jp blog" href="/blog/opensearch.xml" />
</head>
...
</html>
Firefox で検索
OpenSearch に対応したサイトを開き、Firefox 検索バーのプルダウンを開くと
![[Firefox検索バー]](/blog/entries/Misc/20090319_01/firefox_opensearch_01.png)
の様に検索バーへの登録メニューが表示される。登録を行い、検索をしてみると・・・
![[検索を実行]](/blog/entries/Misc/20090319_01/firefox_opensearch_02.png)
検索できた。



