【问题标题】:Contentful search for field which value also has a field内容搜索字段的值也有一个字段
【发布时间】:2018-10-03 12:36:55
【问题描述】:

假设我在内容丰富的后端列出了多部电影,我只想通过查询返回恐怖电影,因此我按类别过滤。

0:fields{
    name: "Some horror movie"
    category: {sys: {…}, fields: {…}} // fields contains in this example: {name: "horror"}
}

请注意,category 本身就是一个内容类型,并且有一个 fields 属性,其中只有一个 name 属性。 所以我想我可以通过执行以下操作来过滤它:

client.getEntries({
      'content_type': 'movie',
      'fields.category.fields.name[match]': 'horror'
    })

虽然这会返回 400 错误,但我真的不知道为什么或如何解决这个问题。

【问题讨论】:

    标签: javascript contentful


    【解决方案1】:

    查询是正确的,但在过滤字段值时,您还需要对引用的内容类型进行过滤。你可以在这里阅读更多信息:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references

    如果您将此添加到您的查询中,它应该可以工作。

    client.getEntries({
      'content_type': 'movie',
      'fields.category.fields.name[match]': 'horror',
      'fields.category.sys.contentType.sys.id': 'horror-content-type-id'
    })
    

    您可以在此处找到完整的 sn-p 示例:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references/search-on-references/console/js

    记得将'horror-content-type-id'替换为恐怖内容类型的实际ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      相关资源
      最近更新 更多