neo4j查找父节点是否存在关系 [英] neo4j find parent node is relationship exists

查看:433
本文介绍了neo4j查找父节点是否存在关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发类似Google驱动器的产品。现在是第二阶段。我一直在进行密码查询,需要帮助。

I am trying to develop a product like a google drive. This is the second phase now. I am stuck in making cypher query and I need help.

用户A可以与组或另一个用户B共享文件/文件夹。

a user A can share a file/folder with a group or another user B.

情况1:用户A共享了由其他子文件夹组成的文件夹。用户B将看到共享文件夹。但是,现在用户A共享了一个子文件夹,用户B再次只能看到根文件夹。

case 1: user A, shared the folder which consists of other subfolders. user B would see the shared folder. however, now user A shared a subfolder, and again user B should see only the root folder.

情况2:用户A当时共享了唯一的子文件夹,用户B将仅看到共享的子文件夹

case 2: user A, shared the only subfolder then, user B will only see a shared subfolder

基本上,我需要从下到节点遍历该节点的父节点,并以CAN_ACCESS_DIR关系遍历其父节点,并在具有此关系的第一个节点处停止

basically I need to traverse the node from bottom to its parent and their parent with CAN_ACCESS_DIR relationship if any and stop at the first node with this relationship

请帮助

已附加图像方案->
查找JAVA2的根(JAVA),并检查它是否已与同一组或用户共享(CAN_ACCESS_DIR)。如果是,那么我们将仅发送JAVA文件夹。如果不是,则仅发送JAVA2文件夹

attached image scenario -> find the root (JAVA) of JAVA2 and check if it has been shared (CAN_ACCESS_DIR) with the same group or a user. If yes, then we will send only the JAVA folder. If not then send only JAVA2 folder

match (g:group) where g.name = "group1" 
match p = (d:directory { name: "JAVA2"})<-[:LEAF | CONTAINS*0..]-(a:directory) where (d)<-[:CAN_ACCESS_DIR]-(g)
unwind nodes(p) as i
return collect(distinct(i)) as result

match (u:user) where u.name = "John"
match (t:tower) where t.name = "Genome"
match (d:directory) where d.name = "Root"
match (u)-[:MEMBER_OF_GROUP]->(g:group)
match (d)-[:CONTAINS*0..]->(s) where (s)<-[:CAN_ACCESS_DIR]-(g)<-[:MEMBER_OF_GROUP]-(u)

不是neo4j的专家,请指导我。谢谢

not an expert in neo4j, please guide me out. thanks

推荐答案

[更新]

此查询应返回该组-可访问的 a 目录,该目录最接近根目录,从特定的(子)目录开始:

This query should return the group-accessible a directory that is closest to the root, starting at a specific (sub)directory:

MATCH p=(g:group)-[:CAN_ACCESS_DIR]->(d:directory)<-[:CONTAINS*0..]-(a)
WHERE g.name = "group1" AND d.name = "JAVA2"
MATCH (a)<-[:CAN_ACCESS_DIR]-(g)
RETURN p, a
ORDER BY LENGTH(p) DESC
LIMIT 1

因为只有一个 MATCH 子句将滤除相同关系的多种用法,此查询使用2个 MATCH 子句允许相同的 CAN_ACCESS_DIR 两次匹配,以防 d 是唯一可访问的目录(因此与 a 相同)。

Since a single MATCH clause would filter out multiple uses of the same relationship, this query uses 2 MATCH clauses to allow the same CAN_ACCESS_DIR relationship to match twice, in case d is the only accessible directory (and therefore the same as a).

这篇关于neo4j查找父节点是否存在关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆