我想找到两个节点之间的所有路径。我使用了这些代码:
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。
关于java - Neo4j 中两个节点之间的所有路径与 TraversalDescription 返回不正确的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23320935/