启用Google附加链接搜索框

Un4*_*v3n 2 schema.org json-ld google-rich-snippets

我想为网站启用Google Sitelinks Search Box.关键是它的自定义搜索页面是由哈希片段实现的,所以JSON-LD数据片段是这样的:

<script type="application/ld+json">
  {
  "@context": "http://schema.org",
  "@type": "WebSite",
  "name" : "my site",
  "alternateName" : "example.com",
  "url": "http://www.example.com/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "http://www.example.com/Search/#!/Keyword-{search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

当Google尝试从此部分提取信息"required name=search_term_string"以显示附加链接搜索框时,遇到问题:

:   http://schema.org/True
valueName:  missing and required
Run Code Online (Sandbox Code Playgroud)

我怀疑Google可能只是期望查询字符串中的搜索字符串而不是散列片段,除了重定向之外你还建议什么?

Un4*_*v3n 5

感谢@unor我找到了解决方案,所以最终代码是这样的:

<script type="application/ld+json">
        {
          "@context": "http://schema.org",
          "@type": "WebSite",
          "name" : "example",
          "alternateName" : "example.com",
          "url": "http://www.example.com/",
          "potentialAction": {
            "@type": "SearchAction",
            "target": "http://www.example.com/Search/#!/Keyword-{search_term_string}/",
            "query-input": {
        		"@type": "PropertyValueSpecification",
        		"valueRequired": true,
        		"valueMaxlength": 100,
        		"valueName": "search_term_string"
    		}
          }
        }
</script>
Run Code Online (Sandbox Code Playgroud)

  • @Waki和HosseinBakhtiari:请注意[这是Google测试工具中的一个错误](http://stackoverflow.com/a/31145753/1591669),现已修复.所以原始标记似乎再次起作用. (2认同)