I have a graph representing users and some articles they wrote. I need to create something like an activity stream including the articles wrote by the user and also by its friends.
I can have all the user's friends’ posts like this:
g.v(4).out("KNOWS").out("POSTED")
and returns
v[9]
v[11]
But I also need to include the posts from the original user retrieved with query:
g.v(4).out("POSTED")
this returns
v[10]
How can I have all the posts without having to do 2 queries and then merging them later? I need to get something like this in return:
v[9]
v[10]
v[11]
Thanks
PD: I'm using Gremlin and Neo4jClient but if anyone have a better solution with something else its will be fine too, at this point I still can change some of the tools I'm using
Use Gremlin's aggregate step and Groovy's unique method:
posts = []
g.v(4).out('POSTED').aggregate(posts).iterate()
g.v(4).out('KNOWS').out('POSTED').aggregate(posts).iterate()
return posts.unique()
See...