2

我完全不知道如何将 Google 的附加链接搜索框与 Google 的自定义搜索结合使用。

有人知道我是如何开始连接 2 的吗?

对于站点链接搜索框,Google 提供以下代码:

<script type="application/ld+json">
{
   "@context": "http://schema.org",
   "@type": "WebSite",
   "url": "https://www.example-petstore.com/",
   "potentialAction": {
     "@type": "SearchAction",
     "target": "https://query.example-petstore.com/search?q={search_term_string}",
     "query-input": "required name=search_term_string"
   }
}
</script>

然后你就有了谷歌的自定义搜索代码:

<script>
  (function() {
    var cx = '006674923042857018221:WMX2084923030';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>

我到底如何连接2?希望你能指出我正确的方向。

4

1 回答 1

1

在 Google 提供的 Javascript 代码中有一个var cx = 'YOUR_LONG_CX_KEY. 使用它来填写potentialAction.target此 URL 模式:

 "target": "http://www.google.com/cse?cx=YOUR_LONG_CX_KEY&q={search_term_string}",

您可以通过在浏览器中使用您自己的搜索字词字符串点击它来确认该 URL 是否有效。

但是,我不知道谷歌是否会接受这一点,因为他们的“目标”字段的文档说,“这必须是一个 URL 模式,它指向与正在搜索的内容位于同一域的地址。” 另一方面,同一页面的顶部显示,“您的网站没有搜索引擎?您可以使用 Google 自定义搜索引擎设置一个。”

于 2015-01-16T23:55:48.423 回答