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

PostGraphile中OR过滤功能失效,无法实现多字段搜索

多字段OR搜索的GraphQL查询修正

你当前的查询写法有误,导致OR逻辑不生效。现在的写法是将surname条件与or字段同级,这会被解析成同时满足surname包含搜索词,并且firstname包含搜索词的逻辑,自然返回空结果。

正确的多字段OR搜索写法,需要把所有要进行逻辑判断的条件放在or数组中:

query SearchQuery($searchTerm: String) {
  allArtists(
    filter: {
      or: [
        {surname: {includesInsensitive: $searchTerm}},
        {firstname: {includesInsensitive: $searchTerm}}
      ]
    }
  ) {
    edges {
      node {
        firstname
        surname
      }
    }
  }
}

这样就能实现「surname包含搜索词,或者firstname包含搜索词」的搜索逻辑,符合你的需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 00:07:08