【问题标题】:How to let Google detect a site search engine?如何让谷歌检测网站搜索引擎?
【发布时间】:2012-12-14 11:45:05
【问题描述】:

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

情况确实如此,因为写入stackoverflow.com<Tab>test<Enter> 会使Chrome 浏览here 而facebook.com<Tab>test<Enter> 什么都不做,因为制表键制表符超出了地址行。

然后我想知道的是如何向谷歌表明我的网站有一个搜索引擎,以及谷歌需要如何格式化查询,以便在使用标签搜索功能时将 Chrome 用户正确重定向到我的网站。是元标签吗?在 robots.txt 中吗?

【问题讨论】:

标签: google-chrome


【解决方案1】:

经过一番挖掘,我找到了描述此内容的 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>

【讨论】:

  • 我看不到 rel="search" 或 在 auctions.yahoo.co.jp 的首页的源代码中任何提及“开源”, 或对于我作为搜索结果返回的任何页面,所以这个故事肯定有更多内容。也许是因为这个答案和今天已经过去了 7 年。
【解决方案2】:

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

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

我从Search Engine Autodiscovery: Google Chrome Autodiscovery 的说明开始,上面写着:

有趣的是,自动发现仅在搜索引擎位于首页时才有效。您必须有一个类型为 search 或类型为 text 且名称为 s 的输入字段:

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

或

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

我让 Chrome 在我的网站 klingonska.org 上自动检测搜索引擎,而不使用 OpenSearch 描述。

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

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

关键因素似乎是表单位于根页面http://&lt;domain&gt;/ 页面(不是像http://&lt;domain&gt;/&lt;dir&gt;/&lt;something&gt;.html 这样的子页面)。而且,IIRC,搜索表单只包含一个字段。

【讨论】:

  • 它似乎也可以使用名为“q”的参数(就像 Google 一样)。
  • @LewisKelsey 我看不出它不会的原因,但还没有尝试过。如果可以,请尝试一下,然后将其添加到上面的答案中。 :)
猜你喜欢
  • 2014-03-01
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 2019-09-19
  • 2011-04-22
  • 1970-01-01
  • 2017-05-24
  • 1970-01-01
相关资源
最近更新 更多