【问题标题】:How to do intersection of traversals in gremlin如何在gremlin中进行遍历的交集
【发布时间】:2020-03-31 01:34:31
【问题描述】:

假设我有 2 个匿名遍历 A 和 B。遍历 A 的结果是 V[1]、V[2]、V[3],遍历 B 的结果是 V[3]、V[4]和 V[5]。

A 和 B 都在搜索不在任何单个顶点中的属性。

“A”遍历搜索V[1]中的属性(x == y),V[1]连接到作为遍历结果的一部分的V[2]和V[3]。

“B”遍历搜索V[5]中的属性(u == w),V[5]连接到作为遍历结果的一部分的V[3]和V[4]。

如何找到这些结果的交集?

我试过了:

__.and(A, B)

但是这样的结果不是交集。

例如:

A = __.has('name', 'marko').out()

B = __.has('name', 'josh').out()

__.and(A, B) 不正确。

注意:为简单起见,采用上述示例。在实际查询中,A & B 相当大,每个都有多个联合。

我浏览了以下链接:

https://groups.google.com/forum/#!msg/gremlin-users/6_MRJxBnivo/wT_71IAzCwAJ

gremlin intersection operation

这里的所有建议都提供了一种进行交集的方法,前提是顶点满足所有条件,而这里不是这种情况。

【问题讨论】:

    标签: gremlin tinkerpop tinkerpop3


    【解决方案1】:

    所以你可以尝试做与groupCount的交集步骤:

    g.V().union(
        __.has('name', 'marko').out(),
        __.has('name', 'josh').out()
    ).groupCount().by().unfold()
    .where(select(values).is(gt(1))).select(keys)
    

    另一种方法是使用斯蒂芬在您提到的帖子中建议的简化查询:

    g.V().has('name', 'marko').out().as('a').
    V().has('name', 'josh').out().as('b').
    select('a').
    where('a',eq('b'))
    

    我在这里都试过了: https://gremlify.com/31

    【讨论】:

      猜你喜欢
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      相关资源
      最近更新 更多