简体   繁体   English

ArangoDB 图遍历对不同的顶点类型使用不同的过滤器

[英]ArangoDB graph traversal with different filter for different vertex types

I need to be able to filter arangodb graph traversal by vertex type.我需要能够按顶点类型过滤 arangodb 图遍历。 There are two vertex types, let's say vA and vB.有两种顶点类型,比如说 vA 和 vB。 There is only one type of edge, which can connect _to and _from either type of vertex.只有一种边,可以连接 _to 和 _from 任一类型的顶点。

vA has an attribute 'pfi' with numeric value. vA 具有带有数值的属性“pfi”。 vB has an attribute 'aliases', which is a dictionary (document) of a few attribute/value pairs integer-as-string): integer. vB 有一个属性“别名”,它是几个属性/值对整数作为字符串的字典(文档):integer。 The integer-as-string attribute contain the same sort of data/numbers as the pfi attribute in vA. integer-as-string 属性包含与 vA 中的 pfi 属性相同类型的数据/数字。

I start with each starting vertex p0 (determined earlier in the query).我从每个起始顶点 p0(在查询的前面确定)开始。 Each p0 has attributes "zero point id" and "pfi".每个 p0 都有属性“零点 id”和“pfi”。

I need to traverse in the outbound direction, and only keep the paths where all vertices of type vA have 'pfi' that matches the p0.pfi, and all vertices of type vB have an 'alias' attribute that matches the pfi.我需要沿出站方向遍历,并且只保留 vA 类型的所有顶点都具有与 p0.pfi 匹配的“pfi”的路径,并且所有 vB 类型的顶点都具有与 pfi 匹配的“别名”属性。

FOR p0 in points
    FOR v, e, p IN 1..5 OUTBOUND p0['zero point id'] GRAPH 'grph'
        FILTER p.vertices[*]['pfi'] ALL == p0['pfi']
            OR p.vertices[*]['aliases'][TO_STRING(p0['pfi'])] NONE == null
        RETURN {
            'pfi': p0['pfi']
            , 'vertices': p.vertices
            , 'edges': p.edges
        }

I've tried several syntax variations on the above, all with the same behaviour: I get all (unfiltered) paths if I remove the filter, and an empty result with the filter.我在上面尝试了几种语法变体,所有这些都具有相同的行为:如果我删除过滤器,我会得到所有(未过滤的)路径,而过滤器的结果是空的。 I think it's because all paths contain both vertex types, and the logic of the OR does not mean that either condition can be true for any single vertex to pass.认为这是因为所有路径都包含两种顶点类型,并且 OR 的逻辑并不意味着任何一个条件都可以为任何单个顶点通过。

How to I phrase this so that the first condition applies to vA types, and the second to vB types?我该如何表达这一点,以便第一个条件适用于 vA 类型,第二个条件适用于 vB 类型?

I found this: Filter on different graph edge types using ArangoDb AQL , which can be adapted to我发现了这个: Filter on different graph edge types using ArangoDb AQL ,它可以适应

FOR p0 in points
    FOR v, e, p IN 1..5 OUTBOUND p0['zero point id'] GRAPH 'grph'
        LET counter = (
            FOR v2 in p.vertices
                FILTER v2['pfi'] == p0['pfi']
                    OR HAS(v2['aliases'], TO_STRING(p0['pfi']))
            RETURN v2
        )
        FILTER COUNT(counter) == COUNT(p.vertices)
RETURN {
    'pfi': p0['pfi']
    , 'edges': p.edges
}

It works, but it feels like a clumsy workaround.它有效,但感觉就像一个笨拙的解决方法。 Is there a more elegant way?有没有更优雅的方式?

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

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