1

Neo4j will support tree pattern in 2.x versions.(We could not use tree function) We are using 1.9RC1.

I need to get Users with Followers and Friends.

public class User
{
    public long Id { get; set; }
    public string Name { get; set; }
    ...............
}

public class UserModel
{
    public long Id { get; set; }
    public string Name { get; set; }
    public string DetailedInformation { get; set; }
    public IEnumerable<UserModel2> Followers { get; set; }
    public IEnumerable<UserModel2> Friends{ get; set; }
}

public class UserModel2
{
    public long Id { get; set; }
    public string Name { get; set; }
}

I want to get tree structured UserModel response. How can be done via Gremlin..

We were using paths function.

g.v(4582).inE.outV.paths{it}

But there is data duplication problem for it. It returns paths not tree.

PS: We are using C#.

4

1 回答 1

2

如果您查看 tree() 是如何实现的,它只是 path() 在连接点处聚合。连接点是相同深度的顶点。因此,您可以根据 path() 的结果创建自己的树数据结构(--或旧版本 Gremlin 中的 paths())。让我通过示例来解释如何实现它。如果您有一组这样的路径:

[1,2,3,4]
[1,3,5,6]
[1,2,3,5]

然后树表示将是:

      4
     /
  2-3
 /   \
1     5
 \
  3-5-6

巧妙地使用嵌入式 HashMap 将提供您想要的功能。请查看 Pipes 2.x 代码库,了解如何实现 Tree 并根据您的需要进行复制(和调整)。

于 2013-04-23T23:22:57.310 回答