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

Strapi API Rest V3.6.8如何按标题搜索文章?

Strapi 3.6.8 内容API标题/正文过滤解决方案

一、正确的V3过滤语法

Strapi 3.x不支持V4的filters[字段][操作符]写法,必须使用字段后缀格式,以下是针对标题/正文过滤的有效写法:

单条件过滤

  • 标题包含指定内容:
    GET /posts?title_contains=foo
    
    或使用_where数组格式(适配复杂条件场景):
    GET /posts?_where[0][title_contains]=foo
    
  • 正文包含指定内容:
    GET /posts?content_contains=bar
    

多条件组合过滤

  • 且关系:标题包含foo 同时 正文包含bar
    GET /posts?title_contains=foo&content_contains=bar
    
    或_where数组写法:
    GET /posts?_where[0][title_contains]=foo&_where[1][content_contains]=bar
    
  • 或关系:标题包含foo 或者 正文包含bar
    GET /posts?_or[0][title_contains]=foo&_or[1][content_contains]=bar
    

二、过滤失效的排查要点

  1. 权限配置检查
    进入Strapi后台 → 设置 → 角色与权限 → 找到对应API角色(比如Public) → 定位到posts内容类型的find权限 → 确保勾选允许过滤选项,同时开启find权限。

  2. 字段名称验证
    确认Post内容类型中,标题字段的机器名是title、正文字段是content(字段名区分大小写),如果是自定义字段名(如articleTitle),需对应写成articleTitle_contains=foo。

  3. 缓存与请求测试
    清除浏览器缓存或使用无痕模式发起请求,避免旧缓存干扰;也可通过Postman等工具直接发送请求,排除前端缓存问题。

  4. 数据库兼容性
    若使用SQLite,contains模糊查询原生支持;若为MySQL等其他数据库,需确认数据库版本支持对应模糊查询语法,且Strapi数据库连接正常。

内容的提问来源于stack exchange,提问作者Toni Michel Caubet

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 10:01:25