Gremlin - vertex and distance sorted by distance.

49 views
Skip to first unread message

dp

unread,
Oct 15, 2017, 9:56:30 AM10/15/17
to Gremlin-users
Hi

I have Vertices as [{name:"John",location:Geoshape.point(10,20)},{name:"John",location:Geoshape.point(11,21)},{name:"John",location:Geoshape.point(12,22)}]

I would like to fetch vertices nearest to a Geoshape.point(9,9) with in 10km radius.


g.V().hasLabel('PersonInfo').has('location',geoWithin(Geoshape.circle(9,9,10))).match(__.as('loc'),__.as('loc').map{it.get().value('location').getPoint().distance(Geoshape.point(9,9).getPoint())}.as('dis'))

I am able to get the list as 

==>{loc=v[40984688], dis=108.91375866495252}

==>{loc=v[16480], dis=108.91375866495252}

==>{loc=v[4216], dis=108.91375866495252}

==>{loc=v[8248], dis=108.91375866495252}


But I am looking for sorting by distance. match with order().by()  not working. Any help please.

-Thanks in Advance.
dp






Robert Dale

unread,
Oct 16, 2017, 7:39:39 AM10/16/17
to gremli...@googlegroups.com
Looking at your results, we can see that a map is the output of that  traversal. Since you want to order by 'dis', that key must be selected.

// using some mock data
g.inject([
['loc': 'v1', 'point': 7],
['loc': 'v1', 'point': 3],
['loc': 'v1', 'point': 5],
['loc': 'v1', 'point': 1]]).unfold().

match(__.as('a'),__.as('a').map{it.get().get('point')*2}.as('dis')).select('a','dis').
  order().by(select('dis'),incr)

==>[a:[loc:v1,point:1],dis:2]
==>[a:[loc:v1,point:3],dis:6]
==>[a:[loc:v1,point:5],dis:10]
==>[a:[loc:v1,point:7],dis:14]


Robert Dale

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/be409f34-05d4-495b-be4f-12e744adbac5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages