英文:
Or filtering with PostGraphile not working
问题
我尝试在一个查询中使用 OR 和筛选器来搜索多个字段。
query SearchQuery($searchTerm: String) {
allArtists(
filter: {
surname: { includesInsensitive: $searchTerm },
or: { firstname: { includesInsensitive: $searchTerm } }
}
) {
edges {
node {
firstname
surname
}
}
}
}
surname
和 firstname
分别查询时会返回结果,但当与 OR
结合时不会返回结果。
是否可能搜索多个字段?
英文:
I am trying to search multiple fields in one query with the use of the OR and filter.
query SearchQuery($searchTerm: String) {
allArtists(
filter: {surname: {includesInsensitive: $searchTerm}, or: {firstname: {includesInsensitive: $searchTerm}}}
) {
edges {
node {
firstname
surname
}
}
}
Both surname
and firstname
will return results if done separately, however when combining with a OR
it will return no results.
Is it possible to search multiple fields?
答案1
得分: 1
filter
操作将所有选项与AND组合。or
选项接受一个筛选器列表,并将它们与OR组合。由于您只想要OR条件,您需要在OR列表内提供您的选项:
query SearchQuery($searchTerm: String) {
allArtists(
filter: {or: [
{surname: {includesInsensitive: $searchTerm}},
{firstname: {includesInsensitive: $searchTerm}}
]}
) {
edges {
node {
firstname
surname
}
}
}
}
英文:
The filter
takes all options and combines with AND. The or
option takes a list of filters and combines them with OR. Since you only want the OR condition you need to supply your options inside the OR list:
query SearchQuery($searchTerm: String) {
allArtists(
filter: {or: [
{surname: {includesInsensitive: $searchTerm}},
{firstname: {includesInsensitive: $searchTerm}}
]}
) {
edges {
node {
firstname
surname
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论