【问题标题】:Why there is link between parent node and child node in neo4j为什么neo4j中的父节点和子节点之间存在链接
【发布时间】:2020-10-14 10:29:32
【问题描述】:

1.我创建了 Tweet 和 TweetLeaf 节点,然后使用以下代码创建现实

MERGE (n:Tweet {id:'13084664', title:'A'})

MERGE (cl1:TweetLeaf {id:'13085170', title:'AB', reply_to:'13084664'})

MERGE (cl2:TweetLeaf {id:'13085179', title:'TESTING Team', reply_to:'13085170'})

MERGE (cl2:TweetLeaf {id:'13085352', title:'TESTING Team', reply_to:'13085170'})

MERGE (cl4:TweetLeaf {id:'13085443', title:'TESTING Team', retweet_to:'13085352'})

MERGE (cl5:TweetLeaf {id:'13085356', title:'TESTING Team', retweet_to:'13085352'})

//parent and leaf.....
MATCH (parent:Tweet)
MATCH (c:TweetLeaf)
WHERE NOT (c)-[:reply]->() 
AND parent.id = c.reply_to
WITH parent, c
MERGE (c)-[:reply_to]->(parent)
//RETURN c, parent

//leaf to leaf reply_to.....
MATCH (c1:TweetLeaf)-[]-()
WHERE exists (c1.reply_to)

MATCH (d1:TweetLeaf)
WHERE NOT (d1)-[]->() and exists (d1.reply_to)
AND c1.id = d1.reply_to

WITH c1, d1
MERGE (d1)-[:reply_to]->(c1)
//RETURN c1, d1

//leaf to leaf retweet_to....
MATCH (c2:TweetLeaf)
WHERE exists (c2.retweet_to)
AND NOT (c2)-[]->()

MATCH (d2:TweetLeaf)-[]->()
WHERE d2.id = c2.retweet_to

WITH c2, d2
MERGE (c2)-[:retweet_to]->(d2)
//RETURN c2, d2

2.最终的结果应该像下面的截图

但是,在我的输出中,节点 A 和节点 AB 之间没有链接。屏幕截图显示了我的输出图

【问题讨论】:

  • 您的代码对我来说运行良好。您是如何创建输出图的?
  • 代码完全相同

标签: neo4j cypher


【解决方案1】:

您用来生成可视化的查询显然只返回了TweetLeaf 节点,因此neo4j 浏览器只显示了这些节点。

请尝试使用此查询(它返回涉及TweetLeaf 节点的所有长度为 0 或 1 的路径):

MATCH p=(:TweetLeaf)-[*0..1]-()
RETURN p

如果有独立的TweetLeaf 节点,长度为 0 的路径将没有关系。如果您不关心这种极端情况,那么您可以改用p=(:TweetLeaf)--()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多