[英]Path traversal with multiple conditions filter on all vertices
I would like to perform a path traversal where I apply a multiple condition filter on all vertices. 我想执行路径遍历,在所有顶点上应用多条件过滤器。
Basically I would like that every vertices matches either a == true
or b == true
. 基本上,我希望每个顶点都匹配
a == true
或b == true
。
It is easy to do it for one of the two: 使用以下两种方法之一很容易做到:
FOR v, e, p IN 0..5 OUTBOUND 'objects/key' GRAPH 'stix_graph'
FILTER p.vertices[*].a ALL == true
RETURN p
or even both condition reunited: 甚至两个条件重新团聚:
FOR v, e, p IN 0..5 OUTBOUND 'objects/key' GRAPH 'graph'
FILTER p.vertices[*].a ALL == true AND p.vertices[*].b ALL == true
RETURN p
But I don see how I could achieve either a
or b
for on every vertex... 但是我看不到如何在每个顶点上获得
a
或b
...
You can use inline projection or inline filter in order to achieve the result you want. 您可以使用嵌入式投影或嵌入式过滤器来获得所需的结果。
Here is a sample AQL using inline projection: 这是使用内联投影的AQL示例:
FOR v, e, p IN 0..5 OUTBOUND 'objects/key' GRAPH 'graph'
FILTER p.vertices[* RETURN CURRENT.a OR CURRENT.b] ALL == true
RETURN p
Here is a sample AQL using inline filter: 这是使用内联过滤器的AQL示例:
FOR v, e, p IN 0..5 OUTBOUND 'objects/key' GRAPH 'graph'
FILTER COUNT(p.vertices[* FILTER CURRENT.a OR CURRENT.b]) == COUNT(p.vertices)
RETURN p
Important Note: This approach will only perform well if you traverse a relatively small graph. 重要说明:仅当您遍历较小的图形时,此方法才能很好地执行。 If you have really huge and deep graph the performance may suffer as both inline projection and inline filter are considered by ArangoDB query optimizer as a
CalculationNode
. 如果您的图确实很大且很深,则性能可能会受到影响,因为ArangoDB查询优化器将内联投影和内联过滤器都视为
CalculationNode
。 Ie ArangoDB will not stop the traversal on a first vertex where the condition returns false
. 即,ArangoDB不会在条件返回
false
的第一个顶点上停止遍历。 It will have to continue the traversal because the filter condition has a calculated value and it can not know in advance if the result of that calculation is true
of false
for the next vertices. 这将有继续穿越,因为过滤条件有一个计算值,并不能预先知道是否计算的结果是
true
的false
下一个顶点。 So, it will do a bit of extra traversals/calculations under the hood, but it will still return the result you expect. 因此,它会在后台进行一些额外的遍历/计算,但仍会返回您期望的结果。
If you want to apply this filter for a really huge graph I believe the correct approach would be to add a bit of redundancy to your data and put that a == true
or b == true
value into a separate attribute which you can efficiently use in your filter condition. 如果您想将此过滤器用于一个非常大的图形,我相信正确的方法是在数据中添加一些冗余,然后将
a == true
或b == true
值放入一个可以有效使用的单独属性中在您的过滤条件下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.