0

我试图了解 Cypher 中以下查询的输出。

start n=node:node_auto_index(name="root_node")
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with  distinct n,c, b, b1
match  n-[:SC]->c-[:CB]->b-[:CT]->i1, n-[:SC]->c-[:CB]->b1-[:CT]->i2 
with b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return  bname,b1name,i1name,i2name
order by bname,b1name,i1name,i2name;

返回 3680 行

start n=node:node_auto_index(name="root_node") 
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with  distinct n,c, b, b1
match  b-[:CT]->i1, b1-[:CT]->i2 
with b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return  bname,b1name,i1name,i2name
order by bname,b1name,i1name,i2name;

返回 184 行

查询 1 似乎在做笛卡尔,但我无法理解为什么?谁能解释一下?

c-[:CB]->b 是 1:n 的关系。

更新:

当我运行以下查询时,我得到正确的 184 个结果:

start n=node:node_auto_index(name="root_node") 
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with  distinct n,c, b, b1
match  c-[:CB]->b-[:CT]->i1, c-[:CB]->b1-[:CT]->i2 
with n.name as nname,c.name as cname, b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return  nname,cname,bname,b1name,i1name,i2name
order by nname,cname,bname,b1name,i1name,i2name;

这表明将 n 退回到笛卡尔。

n-[:SC]->c 是 1:1 的关系。为什么会这样?

4

1 回答 1

0

你验证过 n 和 c 之间的关系真的是唯一的吗?看着路径的Maybee会有所帮助。尝试

match p1=n-[:SC]->c-[:CB]->b-[:CT]->i1, p2=n-[:SC]->c-[:CB]->b1-[:CT]->i2
return p1,p2

查看其他结果彼此不同的地方。

于 2013-04-09T06:50:29.667 回答