我想找到两个节点之间的所有路径。我使用了这些代码:
TraversalDescription desc = Traversal.description();
desc.uniqueness(Uniqueness.RELATIONSHIP_GLOBAL);
desc.evaluator(Evaluators.returnWhereEndNodeIs(graphDb.getNodeById(12)));
desc.evaluator(Evaluators.includingDepths(3, 3));
desc.relationships(RelTypes.husband_of).relationships(RelTypes.wife_of).relationships(RelTypes.brother_of).relationships(RelTypes.elti_of) ;
Traverser traverse = desc.traverse(graphDb.getNodeById(4), graphDb.getNodeById(12));
但它没有返回正确的路径。它返回的深度超过3的路径。路径也不会以ID为12的节点结束。
答案 0 :(得分:2)
这是(主要)因为TraversalDescription使用流畅的API,总是返回修改后的描述。在其上调用方法并忽略结果无效。所以你应该写
TraversalDescription desc = Traversal.description()
.uniqueness(Uniqueness.RELATIONSHIP_GLOBAL)
.evaluator(Evaluators.returnWhereEndNodeIs(graphDb.getNodeById(12)))
.evaluator(Evaluators.includingDepths(3, 3))
.relationships(RelTypes.husband_of)
.relationships(RelTypes.wife_of)
.relationships(RelTypes.brother_of)
.relationships(RelTypes.elti_of);
Traverser traverse = desc.traverse(graphDb.getNodeById(4), graphDb.getNodeById(12));
那就是说,我看一下PathFinder API。