Cypher变量路径条件过滤

Cypher variable path condition filtering

密码不支持可变路径的条件过滤。只能通过子查询来查找,但是子查询的效率特别低。应该如何优化?

MATCH (account:Account{id:15393163051738})-[edge1:transfer]->(otherAccounts1:Account)
  WHERE edge1.transferDate>1276657248987 AND edge1.transferDate<1330135293550
WITH DISTINCT otherAccounts1 AS otherAccounts1
MATCH (account:Account{id:15393163051738})-[edge1:transfer]->()-[edge2:transfer]->(otherAccounts2:Account)
  WHERE edge1.transferDate>1276657248987 AND edge1.transferDate<1330135293550 AND edge2.transferDate>1276657248987 AND edge2.transferDate<1330135293550
WITH DISTINCT otherAccounts2 AS otherAccounts2, otherAccounts1
MATCH (account:Account{id:15393163051738})-[edge1:transfer]->()-[edge2:transfer]->()-[edge3:transfer]->(otherAccounts3:Account)
  WHERE edge1.transferDate>1276657248987 AND edge1.transferDate<1330135293550 AND edge2.transferDate>1276657248987 AND edge2.transferDate<1330135293550 AND edge3.transferDate>1276657248987 AND edge3.transferDate<1330135293550
WITH COLLECT(DISTINCT otherAccounts1.id) + COLLECT(DISTINCT otherAccounts2.id) + COLLECT(otherAccounts3.id) as otherAccounts
RETURN otherAccounts

你试过这样的事情吗?

MATCH path=(account {id..})-[:transfer*1..2]->(otherAccount:Account))
WHERE ALL (edge IN rels(path) WHERE transferDate >  ...  AND .... )
RETURN COLLECT(DISTINCT otherAccount) AS otherAccounts

正确答案:

MATCH path=(account:Account{id:15393163051738})-[:transfer*1..3]->(otherAccount:Account) WHERE ALL (edge IN relationships(path) WHERE edge.transferDate > 1276657248987 AND edge.transferDate < 1330135293550 ) WITH COLLECT(DISTINCT otherAccount) AS disOtherAccount