简体   繁体   English

遍历者关系方向顺序neo4j java

[英]traverser Relationship direction order neo4j java

I want to traverse a graph with the same relationship but firstly the outgoing and secondly the incoming (in this specific order). 我想遍历具有相同关系的图,但首先是传出的,其次是传入的(按此特定顺序)。 I have found 我已经发现

    traverse(Traverser.Order traversalOrder, 
StopEvaluator stopEvaluator,ReturnableEvaluator returnableEvaluator, 
RelationshipType firstRelationshipType,Direction firstDirection, 
RelationshipType secondRelationshipType,Direction secondDirection)

I havent found any examples on how to fill the fields traversalOrder stopEvaluator, returnableEvaluator 我还没有找到有关如何填充traversalOrder的任何示例Order StopEvaluator,returnableEvaluator

My example code is : 我的示例代码是:

for (Path position : graphDb.traversalDescription()
            .relationships(Wikilections_user.RelTypes.Voted, Direction.OUTGOING)
            .relationships(Wikilections_user.RelTypes.Voted, Direction.INCOMING)
            .evaluator(Evaluators.fromDepth(1))
            .evaluator(Evaluators.toDepth(2))
            .evaluator(Evaluators.includeWhereEndNodeIs(node2))
            .uniqueness(Uniqueness.RELATIONSHIP_PATH)
            //.evaluator(Evaluators.excludeStartPosition())
            .traverse(node1)) {

I want to change the part .traverse(node1)) in order to return only paths where firstly i encounter outgoing and secondly i encounter incoming relationship. 我想更改部分.traverse(node1))以便仅返回其中我首先遇到传出和其次我遇到传入关系的路径。 How is that possible? 那怎么可能?

For more complex behaviour you can supply a custom PathExpander using TraversalDescription.expand() . 对于更复杂的行为,您可以使用TraversalDescription.expand()提供自定义PathExpander A pseudo implementation could look like: 伪实现可能类似于:

class MyPathExpander implements PathExpander {
   Iterable<Relationship> expand(Path path, BranchState state) {
      switch (path.length()) {
         case 0:
          return path.endNode().getRelationships(Wikilections_user.RelTypes.Voted, Direction.OUTGOING);
         case 1:
          return path.endNode().getRelationships(Wikilections_user.RelTypes.Voted, Direction.INCOMING)
         default: 
             return Iterables.empty();

      }
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM