如何在遍历图形时收集 Vertex 上的数据,然后将其与结果一起输出?

How do I collect the data on a Vertex as I traverse a graph, and then output it along with the results?

我正在尝试使用图形数据库为简单的新闻源建模。虽然我没有使用 Neo4j,但我的图表大致遵循以下模型:

http://neo4j.com/docs/snapshot/cypher-cookbook-newsfeed.html

下面的 gremlin 查询从每个用户朋友以及用户自己的 post 中检索最近的 15 个 post。 (稍后我将对其进行排名、过滤和分页)。

g.V().hasLabel("user").has("userid", "john.smith")
     .union(
         out("posted"),
         both("friend").out("posted")
     ).next(15).toList();

问题是我需要检索有关 users 自身的数据。诸如头像 url、显示名称等。此数据作为属性存储在每个 user 顶点上。

我如何在遍历图表时收集这些数据并将其与每个 post 一起输出?

如果能够简单地 return 每个 post 注入一个 user 对象,包含连接到每个 user 顶点的所有属性,那就太好了post:

如有任何帮助,我们将不胜感激。

一种方法是使用 select()

g.V().hasLabel("user").has("userid", "john.smith").as('user')
     .union(
         out("posted"),
         both("friend").out("posted")
     ).as('posts').select('user','posts').next(15).toList();