2011-10-17 105 views
0

如何,我可以添加過濾器來定遍歷:使用過濾器在遍歷的Neo4j

TraversalDescription td = Traversal.description() 
       .breadthFirst() 
       .relationships(RelTypes.KNOWS) 
       .evaluator(Evaluators.excludeStartPosition()).evaluator(Evaluators.atDepth(1)) 

,只有擁有財產Name == John節點將在結果?

回答

0
Evaluator e = new Evaluator() { 

      @Override 
      public Evaluation evaluate(Path arg0) { 
       // TODO Auto-generated method stub 
       if(arg0.endNode().getProperty("Name").equals("John")){ 
        return Evaluation.INCLUDE_AND_CONTINUE; 
       }else{ 
        return Evaluation.EXCLUDE_AND_CONTINUE; 
       } 
      } 
     }; 

     TraversalDescription td = Traversal.description() 
       .breadthFirst() 
       .relationships(RelTypes.KNOWS) 
       .evaluator(Evaluators.excludeStartPosition()).evaluator(Evaluators.atDepth(1)).evaluator(e); 

     return td.traverse(a); 
+0

getProperty()非常慢。我可以使用其他的東西嗎?謝謝! – Evgenii