我有两个顶点Named - UserName和CompanyName,每当用户访问任何公司时,我都会增加边缘字段(即pageVisit)。对于个人结果我得到那些pageVisit值,但我怎么能得到所有用户页面的总和访问?
我想在公司页面上显示总页面访问次数,但我没有找到任何方法来添加边缘值。
答案 0 :(得分:3)
您可以使用sum() step:
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> vUser1 = graph.addVertex("UserName","user1")
==>v[0]
gremlin> vUser2 = graph.addVertex("UserName","user2")
==>v[2]
gremlin> vCompany = graph.addVertex("CompanyName","Company")
==>v[4]
gremlin> vUser1.addEdge('visits',vCompany,'pageVisit',10)
==>e[6][0-visits->4]
gremlin> vUser2.addEdge('visits',vCompany,'pageVisit',20)
==>e[7][2-visits->4]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:3 edges:2], standard]
gremlin> g.V(vCompany).inE('visits').values('pageVisit').sum()
==>30