匹配子句的顺序影响结果

时间:2013-09-12 13:13:57

标签: neo4j cypher

我有这个密码查询...

start u = node(251)
match u -[I:PREFERENCE]-> i,
      i <-[Q:CATEGORY|IS_IN*0..]- q <-[C:JOB|LOCATION]- o,
      o -[J:JOB]-> j -[JL:LABEL]-> jl,
      o -[P:LOCATION]-> p -[PL:LABEL]-> pl
where jl.lang = "en"
  and pl.lang = "en"
return distinct o.title, o.description, type(C) as PreferenceType,
      jl.name as Job, pl.name as Location

......还没有完成工作。问题是,如果我跳过LABEL关系,它会返回预期的结果。但是,如果我将其保留在那里,结果取决于最后两个匹配子句的顺序(o -[J:JOB]-> j -[JL:LABEL]-> jlo -[P:LOCATION]-> p -[PL:LABEL]-> pl)。

如果LOCATION是最后一次,我只会收到基于LOCATION的结果,如果我将JOB放在最后一个位置,则只会显示基于作业的结果。

最后,我想要正确的结果(包括基于LOCATION和JOB的结果),但我也想知道为什么这会有什么不同?

我在这里使用Neo4j 1.9.M03

1 个答案:

答案 0 :(得分:0)

这样可行,但我更喜欢没有WITH

的版本
start u = node(251)
match u -[I:PREFERENCE]-> i,
      i <-[Q:CATEGORY|IS_IN*0..]- q <-[C:JOB|LOCATION]- o
 with distinct o, C
match o -[J:JOB]-> j -[JL:LABEL]-> jl,
      o -[P:LOCATION]-> p -[PL:LABEL]-> pl
where jl.lang = "en"
  and pl.lang = "en"
return o.title, o.description, type(C) as PreferenceType,
      jl.name as Job, pl.name as Location
相关问题