Neo4j Java:从多个起点进行遍历 [英] Neo4j java: Traversal from multiple start points

查看:288
本文介绍了Neo4j Java:从多个起点进行遍历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Neo4j 2.0嵌入式系统中的任务是查找从多个节点到树的根的路径,树的所有节点都位于其中.

my task in Neo4j 2.0 embedded is to find the paths from multiple nodes to the root of the tree, in which all nodes are located.

因此,如果我们假设我有起始节点A,B和C,我想找到路径

Thus, if we assume I have start nodes A, B, and C, I'd like to find paths

A-->...-->root
B-->...-->root
C-->...-->root

对于此任务,我定义了一个TraversalDescription,当将其分别应用于每个起始节点时,它的工作效果很好.现在,我看到TraversalDescription的遍历方法不仅可以采用一个起始节点,而且可以采用多个.因此,我将所有起始节点都放入一个数组中,并将该数组传递给遍历方法,如下所示:

For this task, I defined a TraversalDescription which works just fine when applied to each of the start nodes individually. Now I saw that the TraversalDescription's traverse method can not only take one start node but multiple. So I put all my start nodes into an array and passed this array to the traverse method like this:

Node[] startNodes = new Node[3];
startNodes[0] = node1;
...
Traverser traverse = td.traverse(startNodes);
for (Path p : traverse)
  System.out.println(p);

在这里,我希望能将我上面绘制的所有路径都找回来.但是,我似乎只获得起始节点数组中第一个元素的路径,即只有一个路径,尽管每个起始节点都有一个不同的路径.

Here I expected to get all the paths back I sketched above. However, I only seem to get the path for the first element in the start node array, i.e. only one path although there exists one different path for each start node.

现在我的问题是:怎么了?我打算如何使用该方法,还是我使用不正确?

Now my question is: What is wrong? My intention of how the method should work or am I just using it incorrectly?

非常感谢您的回答,想法和提示!

Thank you very much for answers, ideas and hints!

推荐答案

您的完整遍历描述如何?我猜您正在使用错误的唯一性设置.默认值为NODE_GLOBAL,它只能允许遍历访问任何节点一次.我建议使用use NODE_PATH.

How does your full traversal description look like? I'm guessing you're using the wrong uniqueness setting. The default is NODE_GLOBAL, which can only allow the traversal to visit any node once. I would recommend using use NODE_PATH.

这篇关于Neo4j Java:从多个起点进行遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆