[英]ArangoDB Traversal with conditions on vertice's neighbours
I have the following graph: 我有以下图形:
I'd like to write a AQL query that returns paths, starting from the node Q1
, in which the second node in the path has the neighbour P6
(neighbours of the start node Q1
always have a P-node ( P6
, P4
, ..) in its neighbourhood). 我想编写一个AQL查询,该查询返回从节点Q1
开始的路径,其中路径中的第二个节点具有邻居P6
(起始节点Q1
邻居始终具有P节点( P6
, P4
,.. 。)。
For example, the good paths are : Q1->Q1-P6-3->STRING-2
, Q1->Q1-P6-3->Q1-P6-3-QUAL-P2-2->QUANT-2
, etc. What is the best way to check the condition? 例如,好的路径是: Q1->Q1-P6-3->STRING-2
, Q1->Q1-P6-3->Q1-P6-3-QUAL-P2-2->QUANT-2
等。检查状况的最佳方法是什么? For now, I've added to nodes such as Q1-P6-3
an attribute property
with the key of P-node from its neighbourhood and just filter paths: 现在,我已经向Q1-P6-3
的节点添加了一个属性property
,该属性的P节点的关键字来自其邻居,并且仅过滤路径:
FILTER p.vertices[1].property == 'P6'
But I believe there is a smarter way to do that. 但是我相信有一种更明智的方法。 Thank you in advance! 先感谢您!
The AQL first gets the list of all nodes that have P6 as a direct neighbor and then uses that to filter the paths in the traversal query. AQL首先获取将P6作为直接邻居的所有节点的列表,然后使用该列表来过滤遍历查询中的路径。 This way you do not need to keep track of the property in the vertices: 这样,您无需跟踪顶点中的属性:
LET p6Neighbors = (FOR t IN testEdge
FILTER t._to == 'test2/P6'
RETURN t._from)
for v,e,p in 1..5 ANY 'test2/Q1' testEdge
FILTER p.vertices[1]._id in p6Neighbors
return p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.