Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

titan - Graph DB: Sort product based on likes

I have a product vertex which has incomming like edge.

    User ------- likes ----------->products

In my search result I want to sort the products based on likes. How this can be done ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just use 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...