如何解决如何在密码allShortestPaths中正确使用谓词
摘要
我具有以下图形结构,其想法是manager
在给定的permissions
上具有一定的resources
,如图所示,它具有三种资源和一种上下文(管理器)。此外,我们看到了对资源的继承。 break
由shift
拥有。并且lunch
由中断拥有。我想设计一个查询,该查询返回从管理器到每个资源的所有最短路径。例如,从manager
到shift
的最短路径将是permission
关系,该关系是从允许允许字段的管理者那里看到的。问题在于找到最短的突破路径。理想情况下,我希望通过轮班而不是通过午餐到达break
的最短路径。换句话说,对于父级存在的权限将被继承给没有任何直接权限
我尝试过的事情: 我确实编写了正确的查询,但这是我的问题-结果正确地消除了一些资源
代码
这是我到目前为止尝试过的查询。它正确地计算了一条捕获资源的最短路径-它同时考虑了到达break
的最短路径。一个通过lunch
[不应该发生],另一个通过shift [我想要这个]。此外,它完全省略了转移,因为它纯粹是“祖先”(请参阅查询),而不是我理解的“孩子”。
MATCH (ancestors:Resource)<-[:OWNED_BY*..15]-(child:Resource)
MATCH (principal:Resource{id: "p-id"})<-[grant:GRANTED_TO]-(context:Context{id:"c-id"})-[permission:PERMISSION]->(ancestors),path = allShortestPaths((context)-[*..15]-(child))
RETURN DISTINCT path
这是在我的浏览器中执行时查询的输出。
{
"start": {
"identity": 22,"labels": [
"Context"
],"properties": {
"name": "manager","id": "adef1b8c-3141-44bc-a1ec-1644fa6db79a"
}
},"end": {
"identity": 41,"labels": [
"Resource"
],"properties": {
"name": "break","context_id": "","id": "b8519676-312a-4ba4-8004-404c7d782706","source_id": "break-guid"
}
},"segments": [
{
"start": {
"identity": 22,"labels": [
"Context"
],"id": "adef1b8c-3141-44bc-a1ec-1644fa6db79a"
}
},"relationship": {
"identity": 4,"start": 22,"end": 20,"type": "PERMISSION","properties": {
"permitted": "allow","name": "read","id": "dad8b6a0-b039-4105-87d4-ca151963e1a7"
}
},"end": {
"identity": 20,"labels": [
"Resource"
],"properties": {
"name": "shift","id": "2ba8d928-d534-4179-9fad-c85f584ce6d5","source_id": "guid"
}
}
},{
"start": {
"identity": 20,"source_id": "guid"
}
},"relationship": {
"identity": 21,"start": 41,"type": "OWNED_BY","properties": {
}
},"source_id": "break-guid"
}
}
}
],"length": 2.0
}
{
"start": {
"identity": 22,"relationship": {
"identity": 24,"end": 60,"properties": {
"permitted": "deny","id": "9b52f239-43b5-4b17-a29a-91bfeebca001"
}
},"end": {
"identity": 60,"properties": {
"name": "lunch","id": "8c96482d-517f-4421-b1e8-4f4826438cf1","source_id": "lunch-guid"
}
}
},{
"start": {
"identity": 60,"source_id": "lunch-guid"
}
},"relationship": {
"identity": 23,"start": 60,"end": 41,"source_id": "lunch-guid"
}
},"source_id": "lunch-guid"
}
}
}
],"length": 1.0
}
有什么办法可以写出一条查询,为我提供所有资源的最短路径(权限),并且如果没有最短路径,请获取直接父级的权限。任何帮助将不胜感激。谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。