0

我需要返回“帖子”顶点,但是这些帖子有一些“喜欢”的边缘,我怎样才能返回该帖子的“喜欢”边缘的计数作为该边缘的属性,如下所示:

{标题:'lorem ipsum.....',内容:'yadayadayada', 喜欢:6 <----}

4

1 回答 1

5

以 TinkerPop 的现代玩具图为例,您可以执行以下操作:

gremlin> g.V().as('a').
......1>   map(outE('created').count()).as('count').
......2>   select('a','count').by(valueMap()).by()
==>[a:[name:[marko],age:[29]],count:1]
==>[a:[name:[vadas],age:[27]],count:0]
==>[a:[name:[lop],lang:[java]],count:0]
==>[a:[name:[josh],age:[32]],count:2]
==>[a:[name:[ripple],lang:[java]],count:0]
==>[a:[name:[peter],age:[35]],count:1]

它返回“a”中顶点的属性和“已创建”边的计数。您也可以选择使用project()

gremlin> g.V().
......1>   project('a','knows','created').
......2>     by(valueMap()).
......3>     by(outE('knows').count()).
......4>     by(outE('created').count())
==>[a:[name:[marko],age:[29]],knows:2,created:1]
==>[a:[name:[vadas],age:[27]],knows:0,created:0]
==>[a:[name:[lop],lang:[java]],knows:0,created:0]
==>[a:[name:[josh],age:[32]],knows:0,created:2]
==>[a:[name:[ripple],lang:[java]],knows:0,created:0]
==>[a:[name:[peter],age:[35]],knows:0,created:1]
于 2017-09-26T10:34:36.530 回答