如何让Google检测网站搜索引擎?

时间:2012-12-29 14:25:52

标签: google-chrome

Google Chrome浏览器具有以下功能:您可以点击标签来搜索网站。 Chrome然后导航到该网站自己的搜索引擎并运行输入的查询。 Chrome文档表明,仅当Google在您尝试搜索的网站上检测到搜索引擎时,才能使用此文档。

这确实是一种情况,因为撰写stackoverflow.com<Tab>test<Enter>会让Chrome导航herefacebook.com<Tab>test<Enter>什么都不做,因为标签键标签位于地址行之外。

我想知道的是如何向Google表明我的网站有搜索引擎以及Google如何格式化查询,以便在使用标签搜索功能时将Chrome用户正确地重定向到我的网站。它是Meta标签吗?是在robots.txt吗?

2 个答案:

答案 0 :(得分:15)

经过一番挖掘后,我发现this页面描述了这一点。您还可以阅读Stackoverflow的源代码并找到以下代码行:

<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">

它的作用是向Google表明如何在文件/opensearch.xml中使用您的搜索引擎的描述:

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>Stack Overflow</ShortName>
  <Description>Search Stack Overflow: Q&amp;A for professional and enthusiast programmers</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">http://sstatic.net/stackoverflow/img/favicon.ico</Image>
  <Url type="text/html" method="get" template="http://stackoverflow.com/search?q={searchTerms}"></Url>
</OpenSearchDescription>

答案 1 :(得分:0)

当我为在线Klingon词典实现搜索功能时,发现不需要Chrome的OpenSearch描述即可将其自动检测为搜索引擎。

注意:虽然这是一种较为简单的方法,但它不允许使用高级功能,例如指定搜索模板,自定义图标(Chrome会自动使用网站的图标)等。对于其他浏览器也可能不起作用浏览器而不是Chrome。

我从Search Engine Autodiscovery: Google Chrome Autodiscovery这里的说明开始,说:

  

有趣的是,仅当搜索引擎位于主页时,自动发现才起作用。您必须具有类型为{{1}的search或类型为text的类型s的输入字段:

<form>
  <input type="search" name="s" />
</form>
     

<form>
  <input type="text" name="s" />
</form>

我让Chrome浏览器自动检测了我的网站klingonska.org上的搜索引擎,而无需使用OpenSearch描述。

但是,我偏离了上面的描述,因为我发现我不必非要使用名为s的字段也不需要使用type="search"。我的最终<form>看起来像这样(简化形式)。

<form method=get action="dict/">
  <input name=q placeholder="Search dictionary…">
  <button type=submit>Search</button>
</form>

关键因素似乎在于表单位于根页面http://<domain>/页面上(不是http://<domain>/<dir>/<something>.html这样的子页面上)。而且,IIRC,搜索表单仅包含一个字段。

相关问题