2015-02-09 70 views
1

我想遍歷一個具有相同關係的圖,但首先是傳出,其次是傳入(按此特定順序)。我發現遍歷器關係方向order neo4j java

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

我還沒有找到如何填寫traversalOrder stopEvaluator領域的任何例子,returnableEvaluator

我的示例代碼:

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)) { 

我想改變部分.traverse( node1)),以便只返回首先遇到傳出的路徑,其次我遇到傳入的關係。 這怎麼可能?

回答

1

對於更復雜的行爲,您可以使用TraversalDescription.expand()提供自定義PathExpander。僞實現可能看起來像:

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(); 

     } 
    } 
}