Graph databases 社交媒体用例的图形/小精灵查询

Graph databases 社交媒体用例的图形/小精灵查询,graph-databases,gremlin,amazon-neptune,Graph Databases,Gremlin,Amazon Neptune,我的是一个类似社交网络的场景。我想让我跟随的人“张贴”所有帖子。对于这些帖子中的每一篇,我想知道我是否喜欢它,以及帖子中的喜欢和评论的数量(仅计算),以及最近的3条评论,包括所有属性和被评论用户的所有属性,如他的名字等。在gremlin中获得这些内容的最佳解决方案是什么(可能避免重复) 注释的边应该有一个timestamp属性,这就是为什么下面的查询中仍然有todo,但是我想自己应该很容易找到剩余部分 g.V().has('user','id',1).as('me'). out('follo

我的是一个类似社交网络的场景。我想让我跟随的人“张贴”所有帖子。对于这些帖子中的每一篇,我想知道我是否喜欢它,以及帖子中的喜欢和评论的数量(仅计算),以及最近的3条评论,包括所有属性和被评论用户的所有属性,如他的名字等。在gremlin中获得这些内容的最佳解决方案是什么(可能避免重复)


注释的
边应该有一个timestamp属性,这就是为什么下面的查询中仍然有todo,但是我想自己应该很容易找到剩余部分

g.V().has('user','id',1).as('me').
  out('follow').as('friend').
  out('posted').as('post').                                     /* all the posts 'posted' by the people I follow */
  project('friend','post','liked','likes','comments','latest').
    by(select('friend')).
    by(select('post').by('postId')).
    by(coalesce(__.in('liked').where(eq('me')).constant('yes'),
                constant('no'))).                               /* whether I have liked it or not                */
    by(inE('liked').count()).                                   /* no of likes                                   */
    by(inE('comments').count()).                                /* comments that post have(only count)           */
    by(__.in('comments').as('comment').                         /* todo: order by time desc                      */
       in('commented').as('user').limit(3).                     /* latest 3 comments                             */
       select('comment','user').
         by(valueMap()).                                        /* with all properties                           */
       fold())
示例图的结果:

==>[friend:v[2],post:post1,liked:no,likes:0,comments:1,latest:[[comment:[id:[c1],text:[hi]],user:[id:[1]]]]]
==>[friend:v[2],post:post2,liked:yes,likes:3,comments:1,latest:[[comment:[id:[c2],text:[nice]],user:[id:[2]]]]]

注释的
边应该有一个timestamp属性,这就是为什么下面的查询中仍然有todo,但是我想自己应该很容易找到剩余部分

g.V().has('user','id',1).as('me').
  out('follow').as('friend').
  out('posted').as('post').                                     /* all the posts 'posted' by the people I follow */
  project('friend','post','liked','likes','comments','latest').
    by(select('friend')).
    by(select('post').by('postId')).
    by(coalesce(__.in('liked').where(eq('me')).constant('yes'),
                constant('no'))).                               /* whether I have liked it or not                */
    by(inE('liked').count()).                                   /* no of likes                                   */
    by(inE('comments').count()).                                /* comments that post have(only count)           */
    by(__.in('comments').as('comment').                         /* todo: order by time desc                      */
       in('commented').as('user').limit(3).                     /* latest 3 comments                             */
       select('comment','user').
         by(valueMap()).                                        /* with all properties                           */
       fold())
示例图的结果:

==>[friend:v[2],post:post1,liked:no,likes:0,comments:1,latest:[[comment:[id:[c1],text:[hi]],user:[id:[1]]]]]
==>[friend:v[2],post:post2,liked:yes,likes:3,comments:1,latest:[[comment:[id:[c2],text:[nice]],user:[id:[2]]]]]

你能提供一个创建一些示例数据的GRMLLIN脚本吗?这是一个例子,你能提供一个创建一些示例数据的GRMLLIN脚本吗?这里是一个例子,请考虑阅读入门教程:如果你有数百万的用户,您可能会负担得起大小合理的集群,这些集群在此类查询中表现得相当好。此外,如果您有大量并发请求,那么缓存将成为一件大事,而这不再是底层存储和查询引擎的问题。Memcached、Redis等用作缓存层时,并不是为处理特定数据库而设计的,您可以将其用于几乎所有事情,你甚至不需要数据库。我不知道这些大公司都在使用什么,但社交网络几乎是图形数据库最常见的用例。最终的决定取决于您的性能、可扩展性和可靠性要求。这就是说,你可以用任何底层数据库技术构建一个社交网站,所以它应该是最适合你的。在TP 3.4.0中,你可以通过(unfold())执行
valueMap()。
。在当前版本中,您可以<代码> unFoLDD()/Value>值映射和Re> <代码>组()/<代码>。请考虑阅读入门教程:如果您有数百万用户,您可能能够负担得起合理大小的集群,在这种查询上表现良好。此外,如果您有大量并发请求,那么缓存将成为一件大事,而这不再是底层存储和查询引擎的问题。Memcached、Redis等用作缓存层时,并不是为处理特定数据库而设计的,您可以将其用于几乎所有事情,你甚至不需要数据库。我不知道这些大公司都在使用什么,但社交网络几乎是图形数据库最常见的用例。最终的决定取决于您的性能、可扩展性和可靠性要求。这就是说,你可以用任何底层数据库技术构建一个社交网站,所以它应该是最适合你的。在TP 3.4.0中,你可以通过(unfold())执行
valueMap()。
。在当前版本中,您可以
展开()
值映射并重新组()它。