Skip to main content
 首页 » 编程设计

python之小叮当 : Multi-Level search to multiple之vertex types

2024年09月07日9mfryf

示例图:Tinker Modern

查询:在第二跳找到Marko的所有直接 friend (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 连接到人和/或 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的值