TinkerPop:对多顶点类型的多级搜索

TinkerPop: Multi-Level search to multiple - vertex types

示例图Tinker Modern

查询:找到Marko的所有直接朋友(person Vertex)和(联合)所有software在第二跳。


尝试失败次数:

Generic Query for first level people:

g.V(1).hasLabel("person").repeat(both()).times(1).emit(hasLabel("person")).hasLabel("person").values("name")

Generic Query for second level/hop software:

g.V(1).hasLabel("person").repeat(both()).times(2).emit(hasLabel("software")).hasLabel("software").values("name")

Attempt to merge above two queries:

g.V(1).hasLabel("person").repeat(both()).times(1).emit(hasLabel("person")).hasLabel("person").repeat(both()).times(2).emit(hasLabel("software")).hasLabel("software").values("name")

我真的不明白 union 是如何工作的,因为它不是合并数据。

g.V(1).union().V(2)
g.V(1).union(V(2))

到目前为止我得到的最好的是,但我想要一些能力来做(marko 连接到人 AND/OR marko 连接到软件):

gremlin> g.V(1).store('x').V(2).store('y').cap('x', 'y')
==>[x:[v[1]],y:[v[2]]]

第一级:

gremlin> g.V(1).hasLabel("person").as("from", "to1", "to2")
            .repeat(both()).times(1).emit(hasLabel("person")).hasLabel("person").as("to1")
            .select("from")
            .repeat(both()).times(1).emit(hasLabel("software")).hasLabel("software").as("to2")
            .project("from", "person", "software")
            .by(select("from").by("name"))
            .by(select("to1").by("name"))
            .by(select("to2").by("name"))

结果:

==>[from:marko,person:vadas,software:lop]
==>[from:marko,person:josh,software:lop]

对于多级增加times

的值