二、 OpenSearch标准(www.opensearch.org)
OpenSearch支持Mozilla Firefox 2.0以上版本及Internet Explorer 7.0.
Firefox 2 supports the OpenSearch description format for search plugins. Plugins that use the OpenSearch description syntax are compatible with IE 7 and Firefox. Because of this, they are the recommended format for use on the web.
Firefox also supports additional search capabilities not included in the OpenSearch description syntax, such as search suggestions and the SearchForm element. This article will focus on creating OpenSearch-compatible search plugins that support these additional Firefox-specific features.
OpenSearch description files can also be advertised as described in Autodiscovery of search plugins, and can be installed programmatically as described in Adding search engines from web pages.
开放式搜索描述文件,
参见http://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox
XML文件描述一个搜索引擎实际上是很简单的,按照下面基本的模版,斜体字部分需要用户根据用户特定搜索插件的需要自定义。
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>engineName</ShortName>
<Description>engineDescription</Description>
<InputEncoding>inputEncoding</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,imageData</Image>
<Url type="text/html" method="method" template="searchURL">
<Param name="paramName1" value="paramName1"/>
...
<Param name="paramNameN" value="paramValueN"/>
</Url>
<Url type="application/x-suggestions+json" template="suggestionURL"/>
<moz:SearchForm>searchFormURL</moz:SearchForm>
</OpenSearchDescription>
1、
ShortName
搜索引擎的短名
2、
Description
搜索引擎的简要描述
3、
InputEncoding
对输入搜索引擎的数据进行编码
4、
Image
基于64位编码16X16大小的搜索引擎标志图片。
5、
URL
描述搜索使用的URL,方法取决于是否使用GET或POST请求来获取结果。模版显示了查询的基本URL。
注意,IE7不支持POST请求。
你可以指定2种URL形式:
type="text/html" is used to specify the URL for the actual search query itself.
type="application/x-suggestions+json" is used to specify the URL to use for fetching search suggestions.
任何一种形式的URL,都可以用于替代用户在搜索条中输入的搜索条件。其他支持的动态查询参数的描述见OpenSearch 1.1 parameters. 参见http://www.opensearch.org/Specifications/OpenSearch/1.1/Draft_3#OpenSearch_1.1_
parameters
怎样在一台服务器执行查询支持,详细的参见Supporting search suggestions in search plugins. http://developer.mozilla.org/en/docs/Supporting_search_suggestions_in_search_plugins
6、
Param
参数需要和查询一起,形成一对如key/value ,当指定值的时候 ,可以将用户在搜索栏中输入的插入到搜索条件中
注意,IE7不支持此元素
7、
SearchForm
URL通过插件的搜索打开网站中的搜索页面,这样为Firefox提供了一种直接访问网站的方法。
注意,这个元素为Firefox特定的,不是OpenSearch说明书中的一部分,我们在上面的例子中使用”moz:”作为XML命名空间前缀来保证其他用户代理不支持这个元素安全的忽略它。
8、
Autodiscovery of search plugins
一个网站提供一个搜索引擎并宣传它,这样Firefox的用户很容易下载和安装此插件。为了支持自动发现,你只需简单地在网站页面增加一行<HEAD>部分:
<link rel="search" type="application/opensearchdescription+xml"
title="searchTitle" href="pluginURL">
斜体字说明如下:
searchTitle
搜索的执行名称,比如”Search MDC” 或是”Yahoo!Search”。这个值对应于你插件文件的ShortName.
PluginURL
XML搜索插件的URL,任何浏览器都可以下载它。
如果你的网站提供多种搜索插件,你可以使他们支持自动发现。例如:
<link rel="search" type="application/opensearchdescription+xml"
title="MySite: By Author" href="http://www.mysite.com/mysiteauthor.xml">
<link rel="search" type="application/opensearchdescription+xml"
title="MySite: By Title" href="http://www.mysite.com/mysitetitle.xml">
这样,你的站点提供的插件不仅是作者搜索而且可以为单独实体的标题。
9、
Troubleshooting Tips:
http://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox#
Troubleshooting_Tips

图8 Safari上的搜索栏
图9 IE7.0上的搜索栏
图10添加搜索插件
图11
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix