简体   繁体   English

连接到多个其他节点的arangodb节点

[英]arangodb nodes connected to multiple others

I'm just getting started with arangodb and have gotten to my first real problem: 我刚刚开始使用arangodb,现在已经解决了我的第一个真正的问题:

Is it possible to search for nodes connected to all of multiple others? 是否可以搜索连接到多个其他节点的节点? This seems like a basic operation for a graph db but I just can't think of a solution. 这似乎是图形数据库的基本操作,但我想不出解决方案。

For reference, if we take the 'knows' example graph I want to know which persons know Charlie AND Dave (which should be only Bob) 作为参考,如果我们使用“知道”示例图,我想知道哪些人知道Charlie AND Dave(应该只是Bob)

knows example graph (not allowed to embed images yet) 知道示例图 (尚不能嵌入图像)

For now my best guess is to start a traversal for all of the "targets" and reduce and filter the response myself, is this really the only way? 现在,我最好的猜测是开始遍历所有“目标”并自己减少和过滤响应,这真的是唯一的方法吗?

EDIT: OK, to further specify I have added another connection, eve knows dave too, but should NOT be returned since she does not know charlie 编辑:好的,要进一步指定我添加了另一个连接,夏娃也知道戴夫,但不应该返回,因为她不知道查理

EDIT2: So far I've come up with this query EDIT2:到目前为止,我已经提出了这个查询

FOR start IN ['persons/charlie', 'persons/dave']
LET knownBy = (FOR v,e,p IN 1 INBOUND start knows
    RETURN v)
FOR p IN knownBy
    COLLECT person = p
    LET knows = (FOR v IN 1 OUTBOUND person._id knows
        RETURN v._id)
    FILTER knows ALL IN ['persons/charlie', 'persons/dave']
    RETURN person

However, this feels a bit unnatural, getting the persons known by 'X' to get the persons that know 'X'... Also, the profiler shows that about a third of the time is used for optimizing the plan, there has to be a better solution, right? 但是,这感觉有点不自然,要让被“ X”认识的人要让了解“ X”的人……而且,分析器显示,大约有三分之一的时间用于优化计划,因此必须是更好的解决方案,对不对?

If we take the knows example and only search for two connected vertices you can start a traversal on one target with a depth of 2 and filter that the third vertex on the path has to be the second target, then you can just return the second vertex on the path. 如果我们以已知示例为例,并且仅搜索两个相连的顶点,则可以在深度为2的一个目标上开始遍历,并过滤路径上的第三个顶点必须是第二个目标,那么您只需返回第二个顶点在路上。

FOR v, e, p IN 2 ANY 'persons/charlie' knows
  FILTER p.vertices[2]._id == 'persons/dave'
  RETURN p.vertices[1]

If you search for more than two vertices, the following query should work well. 如果搜索两个以上的顶点,则下面的查询应该可以正常工作。 It starts a traversal with a depth of 1 and collect every _id of the person neighbors and checks of your targets are all containing in the neighbors. 它开始深度为1的遍历,并收集邻居的每个_id,并且对目标的检查都包含在邻居中。

LET targets = ['persons/charlie','persons/dave']

FOR person IN persons
  FILTER targets ALL IN FLATTEN((
    FOR v, e, p IN 1 ANY person._id knows
    RETURN v._id
  ))
  RETURN person

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM