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
相关产品推荐
相关产品推荐

