简体   繁体   中英

using filters in traversal neo4j

How can I add filter to given traversal :

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

So that only nodes with property Name == John will be in the result ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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