0

I have a dataset with products and orders. For a given product (here PRODUCT 2) I want to find the 5 products that were ordered most in combination with PRODUCT 2.

I have managed to query and sort all associated products with their frequency.

g.V().has('PRODUCT', 'id', '2').as('a').in('purchased').out('purchased').where(neq('a')).groupCount().order(local).by(values, Order.decr)

returns

==>[4:3,6:2,7:2,12:2,13:2,14:2,15:2,1:1,3:1,5:1,8:1,9:1,10:1,11:1,16:1,17:1]

gremlin gives me an array with all the results, so I cannot use the limit step or range step. How could I select only the first five entries of the array?

4

1 回答 1

1

请注意,groupCount()返回的Map不是“数组”。另外,请注意,您已经在使用该机制来做您想做的事情 - Scope.local。两者都limit()可以range()Scope所以你可以这样做:

 g.V().has('PRODUCT', 'id', '2').as('a').
   in('purchased').out('purchased').
   where(neq('a')).
   groupCount().
   order(local).by(values, Order.decr).
   limit(local,5)

值得记住的是 aMap只是一个集合,因此可以解构为它的项目,unfold()在这种情况下:

 g.V().has('PRODUCT', 'id', '2').as('a').
   in('purchased').out('purchased').
   where(neq('a')).
   groupCount().
   order(local).by(values, Order.decr).
   unfold()
   limit(5)
于 2019-08-06T11:28:30.303 回答