[英]ArangoDB - How to find nodes not related to a specific one?
For clarity purpose, step names are used as identifiers 为了清楚起见,将步骤名称用作标识符
I have the following Directed Acyclic Graph (DAG): 我有以下有向无环图(DAG):
What I'm trying to do is select a node, and find all the other nodes that are not connected directly to the selected one, only in an outbound direction. 我想做的是选择一个节点,并仅在出站方向上找到未直接连接到所选节点的所有其他节点。
For example: if I select "root step", my query should only return "test step 3", since it is the only one not connected directly to "root step". 例如:如果我选择“ root step”,则查询应该只返回“ test step 3”,因为它是唯一未直接连接到“ root step”的查询。
However , if I select "test step 2", it should only return "test step 3", and not "test step", because "test step* is at the same level that "test step 2" is. 但是 ,如果我选择“测试步骤2”,则应该只返回“测试步骤3”,而不返回“测试步骤”,因为“测试步骤*”与“测试步骤2”处于同一级别。
For now, here is how I do: 现在,这是我的工作方式:
I store, in every "step", the list of parents it has as an array. 我在每个“步骤”中将其拥有的父母列表存储为一个数组。 (test step has ["root step"], etc.)
(测试步骤具有[“ root step”]等)
My query is as follows ( for test step 2 as an example ): 我的查询如下(以测试步骤2为例):
FOR v, e IN 0..10 OUTBOUND "steps/test step 2" steps_relations
FILTER e._from != "steps/test step 2"
FILTER e._to != "steps/test step 2"
FILTER v._id != "steps/test step 2"
FILTER ["root step"] NONE IN v.parents
RETURN {id: v._key, name: v.name }
For now it returns an empty result instead of the expected ("test step 3"). 现在,它返回一个空结果而不是预期的结果(“测试步骤3”)。 Any help is greatly appreciated
任何帮助是极大的赞赏
I have finally managed to fix this. 我终于设法解决了这个问题。 Here is how I did it:
这是我的做法:
first, I added two fields to each one of my "steps" document: 首先,我在“步骤”文档的每个文档中添加了两个字段:
root: equals true
when it is the root of the tree (like "root step"). 根:当它是树的根时(例如“根步骤”),等于
true
。 Otherwise it simply references the internal ID of the root step 否则,它仅引用根步骤的内部ID
depth: equals to 0 for the root step, but is incremented. 深度:根步长等于0,但增加。 When I add a step to another, the new step's depth equals (parent + 1) ONLY if the result is bigger than the one actually stored.
当我将一个步骤添加到另一个步骤时,仅当结果大于实际存储的结果时,新步骤的深度才等于(父级+ 1)。
Once I have this, my query looks as follows: 一旦有了这个,我的查询将如下所示:
Situation: I want to list all the steps that can be linked to "test step 2" 情况:我想列出所有可以链接到“测试步骤2”的步骤
FOR step, relation IN 0..10 ANY "steps/root step" steps_relations
FILTER step.depth > 1 /* THE DEPTH OF test step 2 WICH IS 1 */
FILTER relation._from != "steps/test step 2"
RETURN item
This returns successfully "test step 3" 这将成功返回“测试步骤3”
You should rather use the min attribute to suppress edges directly connected: 您应该使用min属性来抑制直接连接的边:
FOR v, e IN 2..10 OUTBOUND "steps/test step 2" steps_relations
RETURN {id: v._key, name: v.name }
this way you will only get paths longer than one edge-hop, and the vertices from 2 onwards. 这样,您只会获得比一个边缘跳更长的路径,并且顶点将从2开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.