Neo4j Cypher布尔条件和IN

时间:2017-01-22 16:10:45

标签: neo4j cypher

继续上一个问题Neo4j Cypher query null or IN我已将isPublic属性添加到Tenant节点。

现在,我需要扩展由frant.hartm亲切创建的查询,同时检查parentDchildD租户的isPublic条件。

我已将我的陈述扩展至以下内容:

t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t)

但它失败并出现以下异常:

org.neo4j.ogm.exception.CypherException: Error executing Cypher; Code: Neo.ClientError.Statement.SyntaxError; Description: Invalid input 'W': expected whitespace, comment, '{', node labels, MapLiteral, a parameter, a relationship pattern, '(', '.', '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 1, column 254 (offset: 253))
"MATCH (t:Tenant) WHERE ID(t) in {tenantIds} WITH COLLECT(t) as tenants MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} AND (not(parentD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t))) AND (not (childD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (childD)-[:BELONGS_TO]-(t)))  RETURN ru, u, childD ORDER BY childD.createDate ASC SKIP 0 LIMIT 100"
                                                                                                                                                                                                                                                              ^
    at org.neo4j.ogm.drivers.embedded.request.EmbeddedRequest.executeRequest(EmbeddedRequest.java:175)
    at org.neo4j.ogm.drivers.embedded.request.EmbeddedRequest.execute(EmbeddedRequest.java:66)

现在的完整查询如下:

MATCH (t:Tenant) WHERE ID(t) in {tenantIds} 
WITH COLLECT(t) as tenants 
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) 
WHERE 
id(parentD) = {decisionId} 
AND
 (not(parentD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t))) 
AND
 (not (childD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (childD)-[:BELONGS_TO]-(t)))  
RETURN ru, u, childD 
ORDER BY childD.createDate ASC 
SKIP 0 LIMIT 100

如何修复此查询以支持t.isPublic

1 个答案:

答案 0 :(得分:0)

任何运算符的语法如下:

any(variable IN list WHERE predicate)

请参阅: https://neo4j.com/docs/developer-manual/current/cypher/functions/predicates/#functions-any

您已将t.isPublic放入错误的位置,未在该上下文中定义t并且您需要将其放在内部WHERE子句之后:

any(t in tenants WHERE t.isPublic OR (parentD)-[:BELONGS_TO]-(t))