我想找到两个节点之间的所有路径。我使用了以下代码:
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的节点结尾。
最佳答案
这(主要是因为)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。