我正在尝试使用图形数据库来建模一个简单的新闻提要。虽然我没有使用Neo4j,但我的图大致遵循以下模型:
http://neo4j.com/docs/snapshot/cypher-cookbook-newsfeed.html下面的gremlin查询从每个用户的朋友以及用户自己的帖子中检索最近的15个帖子。(稍后我会对其进行排序、筛选和分页)。
g.V().hasLabel("user").has("userid", "john.smith")
.union(
out("posted"),
both("friend").out("posted")
).next(15).toList();
问题是我需要检索关于users
本身的数据。比如头像url,显示名称等等。这些数据作为属性存储在每个user
顶点上。
当我遍历图形并将其与每个帖子一起输出时,如何收集此数据?
这将是伟大的,简单地能够返回每个帖子注入user
对象,包含连接到每个帖子的user
顶点的所有属性:
方法之一是使用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();