从Contentful更新Algolia时,如何包含链接条目



当发布Contentful条目时,我目前正在使用Contentful webhook自动更新Algolia。

我在Contentful上的内容模型看起来像这样:

MOVIE:
{ title: string,
director: reference }
DIRECTOR:
{ name: string }

我正在通过Contentful网络挂钩向Algolia发送内容。目前,我发送的数据如下:

title: "Vertigo",
director: {
sys: {
type: "Link",
linkType: "Entry",
id: 123456789
} 
}

相反,我希望它是:

title: "Vertigo",
director: {
name: "Alfred Hitchcock"
}

如何包含链接条目的完整数据,而不仅仅是ID?为了记录在案,我使用了一个自定义的webhook有效负载,它看起来基本上是这样的:

{
"title": "{ /payload/fields/title/en-US }",
"director": "{ /payload/fields/director }"
}

根据文档,要遵循链接,您必须超越开箱即用的webhook,编写自己的连接。

根据您的使用情况在webhook中包含引用的项数据如果您可能希望为条目及其链接的所有数据编制索引因为它是由不同的Contentful实体组成的。引用条目数据在webhook负载中不可用建议写你自己的逻辑来养活Algolia。这个有内容的客户端库提供了一种检索链接数据的方法。

来源:https://www.contentful.com/developers/docs/tutorials/general/enhancing-search-experience-with-algolia/

最新更新