neo4j - 为什么neo4j中的父节点和子节点之间存在链接
问题描述
1.我创建了 Tweet 和 TweetLeaf 节点,然后使用以下代码创建 realatioships
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
解决方案
您用于生成可视化的查询显然只返回TweetLeaf
节点,因此 neo4j 浏览器只显示这些节点。
相反,请尝试使用此查询(它返回涉及TweetLeaf
节点的所有长度为 0 或 1 的路径):
MATCH p=(:TweetLeaf)-[*0..1]-()
RETURN p
如果有独立TweetLeaf
节点,长度为 0 的路径将没有关系。如果您不关心这种边缘情况,那么您可以p=(:TweetLeaf)--()
改用。
推荐阅读
- regex - 正则表达式忽略带重复磅的字符串 (#)
- javascript - Javascript:删除字符串之间的空格,除了一个
- wordpress - (wordpress)显示帖子的标题和内容而不是当前页面的标题和内容?
- linux - 在 Linux 中的汇编 x86_64 中的声明处获取字符串长度
- rx-java2 - .doOnComplete() 是否保证在方法实际返回之前执行?
- sql - 在联合 SQL 中添加一个空白列
- dataframe - 从月中删除某些天
- reactjs - 子组件正确删除父状态的对象条目,但重新渲染时卸载错误的子组件
- mysql - 将 MySQL 连接到 Talend 时出错
- react-native - 计算当前位置的经度和纬度