我有一个密码查询,我试图编写等效的遍历描述,但是我被顺序卡住了。

start n=node:EduNodes(title='bachelor of science')
match p=n-[:JOB_CHANGE|EDUCATION|CAREER_ENTRY|EDUCATION_CONTINUED*1..4]->m
with p, relationships(p) as rels, n, m
return p,n,m,
reduce(weight=0, x in rels: weight + x.weight) as totalWeight
order by totalWeight asc


该查询非常消耗内存并且速度很慢,遍历描述很快:

TraversalDescription td = Traversal.traversal().evaluator(Evaluators.excludeStartPosition())
        .uniqueness(Uniqueness.NONE).depthFirst()
        .evaluator(Evaluators.includingDepths(1, 4))
        .relationships(RelationshipTypes.JOB_CHANGE, Direction.OUTGOING)
        .relationships(RelationshipTypes.EDUCATION, Direction.OUTGOING)
        .relationships(RelationshipTypes.CAREER_ENTRY, Direction.OUTGOING)
        .relationships(RelationshipTypes.EDUCATION_CONTINUED, Direction.OUTGOING);


遍历描述中是否也可以包含密码查询的最后两行(降序)?之后我可以自己循环进行。

Traverser traverser = td.traverse(start);
List<PathWrapper> orderedTraversalResult = new ArrayList<>();
for (Path path : traverser) {
    orderedTraversalResult.add(new PathWrapper(path));
}
Collections.sort(orderedTraversalResult);

最佳答案

您可以提供自己的能够处理分支状态的PathEvaluator。最好的资源是Neo4j本身的单元测试,请查看https://github.com/neo4j/neo4j/blob/master/community/kernel/src/test/java/org/neo4j/kernel/impl/traversal/TestBranchState.java

关于java - 遍历描述相当于密码查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25761574/

10-13 02:29