You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drupal9 JSON:API如何按Paragraphs字段过滤文章?

解决方案

问题根源

Paragraphs字段本质是实体引用字段,直接对该字段使用CONTAINS过滤时,匹配的是Paragraph实体的ID而非其内部文本内容,所以无法返回预期结果。

正确过滤方式

需要通过JSON:API的跨实体关系过滤,关联到Paragraph实体内部的具体文本字段进行匹配。以下是实现"标题或Paragraph文本包含关键词"的两种有效请求格式:

格式1:使用关系字段路径

/jsonapi/node/article?filter[group][conjunction]=OR&filter[title][operator]=CONTAINS&filter[title][value]=search term&filter[field_paragraphs.field_text][operator]=CONTAINS&filter[field_paragraphs.field_text][value]=search term

格式2:使用分隔符关联字段

/jsonapi/node/article?filter[group][conjunction]=OR&filter[title][operator]=CONTAINS&filter[title][value]=search term&filter[field_paragraphs--field_text][operator]=CONTAINS&filter[field_paragraphs--field_text][value]=search term

关键注意事项

  • 替换占位符:将field_paragraphs改为你文章类型中实际的Paragraph字段名,field_text改为Paragraph实体里存储文本的目标字段名(比如field_body、field_content等)。
  • 权限验证:确保当前请求用户拥有访问Paragraph实体及其目标文本字段的权限,否则过滤会失效。
  • 多Paragraph类型适配:如果使用了多种Paragraph类型,可额外添加filter[field_paragraphs.type][value]=your_paragraph_type参数,限定仅匹配指定类型的Paragraph内容。

内容的提问来源于stack exchange,提问作者wot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 21:14:58