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

2024-04-20 10:15:29 发布

您现在位置:Python中文网/ 问答频道 /正文

示例图Tinker Modern

查询:在第二跳中查找Marko的所有直接好友(person顶点)和(union)所有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 connected to person和/或marko connected to software):

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

Tags: tonameforsoftwarequerylevelgenericperson
1条回答
网友
1楼 · 发布于 2024-04-20 10:15:29

第一级:

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的值

相关问题 更多 >