我有一个product
顶点,它有like
个边缘。
User ------- likes ----------->products
在我的搜索结果中,我想根据喜欢对产品进行排序。如何做到这一点?
答案 0 :(得分:0)
只需使用groupCount
:
gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> user1 = g.addVertex('u1')
==>v[u1]
gremlin> user2 = g.addVertex('u2')
==>v[u2]
gremlin> product1 = g.addVertex('p1')
==>v[p1]
gremlin> product2 = g.addVertex('p2')
==>v[p2]
gremlin> product3 = g.addVertex('p3')
==>v[p3]
gremlin> user1.addEdge('like',product1)
==>e[0][u1-like->p1]
gremlin> user1.addEdge('like',product2)
==>e[1][u1-like->p2]
gremlin> user2.addEdge('like',product2)
==>e[2][u2-like->p2]
gremlin> user2.addEdge('like',product3)
==>e[3][u2-like->p3]
gremlin> g.v('u1','u2').out('like').groupCount().sort{-it.value}
Cannot invoke method negative() on null object
Display stack trace? [yN] n
gremlin> g.v('u1','u2').out('like').groupCount().cap.next().sort{-it.value}
==>v[p2]=2
==>v[p1]=1
==>v[p3]=1