Google附加链接搜索框,带有Google自定义搜索功能

时间:2015-03-02 11:31:52

标签: google-oauth google-custom-search google-search-api

我们希望使用Google自定义搜索来实施Google附加链接搜索框。在Google documentation中,我发现我们需要包含以下代码才能启用附加链接搜索框

    <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>

但我们在上述属性中停留在“目标”节点。由于我们没有自己的搜索页面,我们希望使用Google自定义搜索,因此我应该在此“目标”节点中填写什么值。

我们已经为我们的网站创建了一个Google自定义搜索引擎。并在下面找到代码

<script>
  (function() {
    var cx = 'CX_ID';
    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>
<gcse:search></gcse:search>

我们希望实施像MashableImdb

这样的附加链接搜索框

enter image description here

请建议如何在附加链接搜索框代码中指向Google自定义搜索。

由于

3 个答案:

答案 0 :(得分:1)

唯一的解决方案:

为此,您需要在自己的网站上搜索页面。

  

对于&#34;目标&#34;参数,在您的网站上搜索并获取该网址,并使用&#34; {search_term_string}&#34;

替换您用于搜索的搜索字词

如果您在自己的网站上创建了使用自定义Google搜索的搜索页面,则应该能够获取target - 属性的链接。

原因是Google不提供搜索功能

  

会将用户直接发送到您网站自己的搜索页面。

来源:

答案 1 :(得分:1)

Shishdem的链接无法确定目标的写入内容,经过一些猜测工作后,

https://example.com/index.html?q={search_term_string}

包含作为index.html页面

的一部分的搜索框

如果搜索框位于站点地图页面上,请使用

https://examples.com/sitemap.html?q={search_term_string}

我只能找到这个因为404页面包含搜索框,所以它返回404然后结果出现,所以我调整了代码。

这忽略了该页面上的任何其他内容并且似乎得出了正确的结果,因此应该适合JSON-LD(或者如果您愿意,还可以使用微数据)。 JSON-LD可能会更好,因为谷歌推荐它,但状态微数据被接受。参考原始问题文档中的链接。

答案 2 :(得分:0)

您需要使用Google CSE WordPress插件: https://wordpress.org/plugins/google-cse/

  1. 安装它。
  2. 启用自定义搜索API
  3. 生成API
  4. 使用您生成的API和自定义搜索引擎ID
  5. 在网站上找到您内置的WordPress搜索
  6. 现在您将能够使用SearchAction Shema.org标记(附加链接搜索框)。

    仅适用于WordPress。