在批量 Feed 中,实体版本通过 Feed 信封中的 dateModified
字段确定:
{
"@context": "http://schema.googleapis.com",
"dateModified": "2018-12-28T06:30:00:123-07:00",
"@type": "DataFeed",
"dataFeedElement": [
/* All the items that are part of this feed go here */
]
}
字段 dataFeedElement
中列出的所有实体的时间戳都将与信封中列出的时间戳相同。
例如,您可以使用以下 Feed,其中有两个实体:
{
"@context": "http://schema.googleapis.com",
"@type": "DataFeed",
"dateModified": "2018-12-28T06:30:00:123-07:00",
"dataFeedElement": [
{
"@type": "Restaurant",
"@id": "http://www.provider.com/somerestaurant",
...
},
{
"@type": "Menu",
"@id": "http://www.provider.com/somerestaurant/menu/1"
...
}
]
}
菜单和餐馆实体在接收和处理后,将分别显示为“2018-12-28T06:30:00:123-07:00”。
通过增量更新进行版本控制
使用目录更新发送实体时,版本通过 update_time
字段(如果是添加/更新调用)或 delete_time
字段(如果是删除调用)设置。由于这些字段是可选的,因此默认时间戳设置为 Google 收到来电的时间。
示例 1:显式设置 update_time
假设在 2018-12-28T06:30:10:123-07:00 收到有关一家新餐厅的以下增量调用。以下是针对该实体的 ID 为“http://www.provider.com/somerestaurant”的 HTTP POST 请求(假设数据 Feed 使用 v1 清单架构):
POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json
下面,JSON 载荷正文包含 update_time
字段。ID 为“http://www.provider.com/somerestaurant”的实体会导致此实体的版本编号为 6:30:00,而不是接收时的版本(延迟 10 秒,在 6:30:10):
{
// This envelope is to be used for incremental.
"entity": {
// Note: "data" is not serialized as a string in our example for readability.
"data": "[entity in JSON format serialized as a string]",
"vertical": "FOODORDERING"
},
"update_time":"2018-12-28T06:30:00:123-07:00"
}
示例 2:隐式设置 update_time
假设在 2018-12-28T06:30:10:123-07:00 收到有关一家新餐厅的以下增量调用。以下是针对该实体的 ID 为“http://www.provider.com/somerestaurant”的 HTTP POST 请求(假设 Feed 使用 v1 产品目录架构):
POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json
在下面,JSON 载荷正文不包含字段 update_time
。因此,ID 为“http://www.provider.com/somerestaurant”的实体会导致此实体的版本为 6:30:10:
{
// This envelope is to be used for incremental.
"entity": {
//Note: "data" is not serialized as a string in our example for readability.
"data": "[entity in JSON format serialized as a string]",
"vertical": "FOODORDERING"
}
}
批量版本和增量版本之间的版本控制
对于发送到 Google 的实体,仅在具有最新版本的情况下才会得到处理和提供。请注意,通过批量发送的实体通常需要几天时间进行处理,而通过增量 API 发送的实体会立即得到处理。
最佳实践
- 根据系统中实体的修改时间,分别以增量方式和批量方式设置
update_time
和dateModified
字段。 - 如果批量 Feed(文件)列出了多个顶级实体(例如,将餐馆与服务和菜单配对),则在实体数据更新时更新时间戳。
- 对于增量调用,我们强烈建议您明确设置
update_time
字段。 - 执行增量调用后,在 Google 再次提取相应 Feed 时间戳 (
dateModified
) 之前,还必须更新该时间戳。
示例
Google 于 2018 年 12 月 28 日上午 11 点为一家全新的餐厅提取了以下文件:
{
"@context": "http://schema.googleapis.com",
"@type": "DataFeed",
"dateModified": "2018-12-28T06:30:00-07:00",
"dataFeedElement": [
{
"@type": "Restaurant",
"@id": "http://www.provider.com/newrestaurant",
...
},
{
"@type": "Menu",
"@id": "http://www.provider.com/newrestaurant/menu/1"
...
}
{
"@type": "Service",
"@id": "http://www.provider.com/newrestaurant/service/1"
...
}
]
}
这些实体会得到成功处理,并且版本控制为“2018-12-28T06:30:00-07:00”。由于批量 Feed 的处理需要一些时间,因此这些 Feed 通常会在 2 天后投放。
但是,在下午 1 点,合作伙伴的系统对餐馆的电话号码进行了更新,从而产生以下增量调用,Google 在 13:05(5 秒后)收到该调用:
POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json
{
// This envelope is to be used for incremental.
"entity": {
//Note: "data" is not serialized as a string in our example for readability.
"data": "[entity in JSON format serialized as a string]",
"vertical": "FOODORDERING"
},
"update_time":"2018-12-28T13:00:00-07:00"
}
update_time
已明确提供,并且比上一个版本(同一天早上 6:30)更大(较新),因此餐馆实体的版本现在为“2018-12-28T13:00:00-07:00”。不过,菜单和服务实体的版本仍为“2018-12-28T06:30:00-07:00”。
由于存在增量调用,因此批处理 Feed 会使用新的相应时间戳进行更新。此外,相应的更改也会应用于相关实体(餐馆实体的电话号码已更新)。
{
"@context": "http://schema.googleapis.com",
"@type": "DataFeed",
"dateModified": "2018-12-28T13:00:00-07:00",
"dataFeedElement": [
{
"@type": "Restaurant",
"@id": "http://www.provider.com/newrestaurant",
...
},
{
"@type": "Menu",
"@id": "http://www.provider.com/newrestaurant/menu/1"
...
}
{
"@type": "Service",
"@id": "http://www.provider.com/newrestaurant/service/1"
...
}
]
}
次日(2018 年 12 月 29 日)晚上 11 点,系统再次提取该 Feed。餐馆的版本仍然相同(12 月 28 日下午 1 点),所以该实体会被丢弃,而当前版本会保留。不过,“菜单”实体和服务实体已更新为新版本。
站点地图时间戳
站点地图中的 last-modified
响应标头不会影响实体的版本。它会影响 Google 抓取 Feed 的时间。
最佳实践
- 仅当所有文件均为最新且可供提取时,才更新响应标头。
- 以增量方式明确使用
update_time
和delete_time
。 - 将
update_time
、delete_time
和dateModified
设置为您这边的数据发生更改的时间。