[英]Filter neighbour's INBOUND vertices with path labels in ArangoDB
I have the following graph:我有下图:
I'd like to write an AQL query that returns all vertices which are neighbor's INBOUND vertices colored in RED from the start vertex colored in GREEN.我想编写一个 AQL 查询,它返回所有顶点,这些顶点是从以绿色着色的起始顶点开始以红色着色的邻居的入站顶点。
I tried the following AQL to retrieve red vertices from the green vertex.我尝试了以下 AQL 从绿色顶点检索红色顶点。
WITH collection_A, collection_W
LET A_Neighbors = (FOR t IN collection_edges
FILTER t._to == 'collection_W/W'
RETURN t._from)
let all_w = []
for item in A_Neighbors
let sub_w = (for v1 in collection_edges
FILTER v1._to == item
return v1 )
return APPEND(all_w, sub_w)
Is there any good solution other than this?除了这个还有什么好的解决办法吗? Because I'm not sure this gives the correct values for start vertex collection_W/W
.因为我不确定这是否给出了开始顶点collection_W/W
的正确值。
My collection_edges
contains following two kind of documents.我的collection_edges
包含以下两种文件。
{
_from: collection_W/w,
_to: collection_A/a,
label: INBOUND
}
and和
{
_from: collection_A/a,
_to: collection_W/w,
label: OUTBOUND
}
Given the diagram, I would suggest using a graph traversal specific [min[..max]]
value, like this (using an anonymous graph ):鉴于该图,我建议使用图遍历特定的[min[..max]]
值,如下所示(使用匿名图):
WITH collection_A, collection_W
FOR vertex IN 2 ANY 'collection_W/W' // green start node
collection_edges
RETURN vertex
The [min[..max]]
value can be a range ( 1..3
) or it can be a single value ( 1
). [min[..max]]
值可以是一个范围 ( 1..3
) 也可以是单个值 ( 1
)。
0
will return the start node 0
将返回起始节点1
will return adjacent nodes 1
将返回相邻节点2
will skip the adjacent nodes and return only nodes at the next level (if any) 2
将跳过相邻节点并仅返回下一级的节点(如果有)2..999
will return all nodes (up to 999 hops away) from the start node 2..999
将从起始节点返回所有节点(最多 999 跳)Further, if you want to make sure that you're only returning nodes from a specific collection, add a filter for that:此外,如果您想确保只返回特定集合中的节点,请为此添加一个过滤器:
WITH collection_A, collection_W
FOR vertex IN 2 ANY 'collection_W/W' // green start node
collection_edges
FILTER IS_SAME_COLLECTION('collection_W', vertex)
RETURN vertex
You can also filter on edges (if you've added a specific attribute/value to your edges):您还可以过滤边缘(如果您已将特定属性/值添加到边缘):
WITH collection_A, collection_W
FOR vertex, edge IN 2 ANY 'collection_W/W' // green start node
collection_edges
FILTER edge.someProperty == 'someValue' // only return vertices that are beyond matching edges
RETURN vertex
Or limit the traversal with PRUNE :或者使用PRUNE限制遍历:
WITH collection_A, collection_W
FOR vertex, edge IN 2 ANY 'collection_W/W' // green start node
collection_edges
PRUNE edge.someProperty == 'someValue' // stop traversal when this is matched
RETURN vertex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.