Google 自定义搜索引擎 Schema.org 结构化数据并通过 API 返回结果

Google Custom Search Engine Schema.org structured data and returned results through API

这是我的带有丰富网页摘要的标记

<div vocab="http://schema.org" typeof="GovernmentOrganization">
<p>
    <span property="logo"><img src="http://www.place.com/image.png" class="logo"/></span>
    <span class="h2" property="name">Department Of Stuff And Things</span><br />
    <span class="h4" property="department">State Agency</span><br />
    <a href="http://www.place.com" class="h4 text-primary" property="url">http://www.place.com</a>
</p>

<strong>Locations:</strong><br /><br />                 
    <div property="location" typeof="GovernmentOffice">
        <p property="location" typeof="PostalAddress">
            Main Office<br />
            <span property="streetAddress">555 Something Street Apt 2</span><br />
            <span property="addressLocality">Jacksonville</span> 
            <span property="addressRegion">FL</span> 
            <span property="postalCode">11111</span><br />
            <span property="addressCountry">US</span>
        </p>
    </div>

<strong>Services:</strong><br /><br />
<div property="hasOfferCatalog" typeof="OfferCatalog">
        <div property="itemListElement" typeof="GovernmentService">
            <p>
                <strong><span property="name">Service 1</span></strong><br />
                <span property="category">Web Based</span><br />
                <span property="description">Get Some stuff and things</span><br />
                <a href="https://www.place.com/Service1" property="url">https://www.place.com/Service1</a><br />
            </p>
        </div>
        <div property="itemListElement" typeof="GovernmentService">
            <p>
                <strong><span property="name">Apply For Benefits</span></strong><br />
                <span property="category">Phone Based</span><br />
                <span property="description">This service helps you apply for the benefits you deserve</span><br />
                <a href="https://www.place.com/Service2" property="url">https://www.place.com/Service1</a><br />
            </p>
        </div>
</div> 

结构化数据测试工具似乎可以适当地组织和验证所有内容,包括我的小型服务集合 (OfferCatalog)。当向自定义搜索 API 发出请求并添加 :more:pagemap:GovernmentOrganization 时,事情似乎没问题,我得到了预期的结果。但是页面映射的 JSON 对象只包含我组织的第一层:

"pagemap": {
"GovernmentOrganization": [
 {
  "name": "Department Of Stuff And Things",
  "department": "State Agency",
  "url": "http://www.place.com"
 },

关于为什么我的相关对象(GovernmentOffice / locations / OfferCatalog / GovernmentServices)没有被包括在内有什么想法吗?有没有更好的方法来组织和构建 Google?

考虑这种方法。在文档中包含以下 JSON-LD 脚本。它可以放在任何地方,但考虑将它放在 RDFa DIV:

之前
<script type="application/ld+json" id="">
{
"@context":
    {
      "@vocab": "http://schema.org/",
      "@base": "http://www.place.com/"
    },
"@graph": [
    {
      "@id": "_:ub220bL18C41",
      "@type": "PostalAddress",
      "addressCountry": "US",
      "addressLocality": "Jacksonville",
      "addressRegion": "FL",
      "postalCode": "11111",
      "streetAddress": "555 Something Street Apt 2"
    },
    {
      "@id": "_:ub220bL4C1",
      "@type": "GovernmentOrganization",
      "department": "State Agency",
      "hasOfferCatalog": {
        "@id": "_:ub220bL6C40"
      },
      "location": {
        "@id": "_:ub220bL17C33"
      },
      "logo": "",
      "name": "Department Of Stuff And Things",
      "url": "http://www.place.com"
    },
    {
      "@id": "_:ub220bL17C33",
      "@type": "GovernmentOffice",
      "location": {
        "@id": "_:ub220bL18C41"
      }
    },
    {
      "@id": "_:ub220bL6C40",
      "@type": "OfferCatalog",
      "itemListElement": [
        {
          "@id": "_:ub220bL12C17"
        },
        {
          "@id": "_:ub220bL7C48"
        }
      ]
    },
    {
      "@id": "_:ub220bL12C17",
      "@type": "GovernmentService",
      "category": "Web Based",
      "description": "Get Some stuff and things",
      "name": "Service 1",
      "url": "https://www.place.com/Service1"
    },
    {
      "@id": "_:ub220bL7C48",
      "@type": "GovernmentService",
      "category": "Phone Based",
      "description": "This service helps you apply for the benefits you deserve",
      "name": "Apply For Benefits",
      "url": "https://www.place.com/Service2"
    }
  ]
}
</script>

您需要更改 @base 到您的网站并决定如何组织您的目录结构以管理您的标识符。然后将每个空白节点更改为适当的标识符。然后最小化 JSON-LD.

JSON-LD 在语义上与 RDFa 相同。因此,您将能够分析 Google pagemap 并决定哪种策略更适合您。如果 JSON-LD 在语义上与 HTML/RDFa 标记相同,我不希望 Google 惩罚页面。

根据 Google:

I believe you are seeing only one value of a attribute in JSON API.

I would like to update you that as per the design in JSON API we show only one attribute value, while in XML we show all values.

We already have a feature request #16696973 to display all the attribute values in JSON API. Currently I don't have an ETA when it will be implemented.

As a workaround you have to use XML API.