与 Neo4j Cypher 中的 where 子句的多次匹配给出错误 "Cannot match on a pattern containing only already bound identifiers"

Multiple match with where clause in Neo4j Cypher gives error "Cannot match on a pattern containing only already bound identifiers"

我们正在使用 neo4j-community-2.1.2。现在我们在数据库中只有 3 个作业标签 的节点并且我们对该查询中使用的所有字段进行架构索引。数据库总点击数 约 40 查询是 ->

   PROFILE match (job1:Job) where (job1.jobType="Adhoc" or job1.jobType="Virtual") AND (job1.mode="Free" or job1.mode="Paid") with collect(job1) as jobs1    
    match (job2:Job)-[REQUIRED_SKILL]-(skill:Skill) where skill.name="Neo4j" and (job2 in jobs1) with collect(job2) as jobs2 
    match (job3:Job)-[REQUIRED_SKILL]-(skill:Skill) where skill.name="Java" and (job3 IN jobs2) with collect(job3) as jobs3 return jobs3

所以我们尝试做类似的事情

match (job1:Job) where (job1.jobType="Adhoc" or job1.jobType="Virtual")
match (job1) where  (job1.mode="Free" or job1.mode="Paid") with collect(job1) as jobs1 return jobs1

因为第一场比赛的结果进入下一场比赛。这样在下一个过滤器中只需要过滤较少数量的节点但是我们得到这个异常

Cannot match on a pattern containing only already bound identifiers (line 2, column 1)
"match (job1) where  (job1.mode="Free" or job1.mode="Paid") with collect(job1) as jobs1 return jobs1"

优化此查询

您不能匹配 job1 两次,一旦匹配您可以再次使用相同的实例(使用 WITH),或者在这种情况下,您可以使用 [=13 在两个条件上进行过滤=].此外,通过将 OR 替换为 IN 包含测试,您的查询会更简单,如下所示:

match (job1:Job) 
  where job1.jobType in ["Adhoc", "Virtual"]
  and job1.mode in ["Free", "Paid"] 
return collect(job1) as jobs1