Database Reference
In-Depth Information
Listing 4.8. Improved traversal definition with a custom evaluator
You'll remember that there's one evaluator already, which includes only nodes at depth
level 2
. The good thing is that you don't need to remove it, but simply add the new
one .IntheNeo4jTraversalAPI,multipleevaluatorscanbecomposedtogether,soyou
can add many evaluators to the single TraversalDescription . If multiple evaluat-
ors are included during the traversal, then Boolean algebra applies: for the current node to
be included in the result, all evaluators must return an Evaluation with an INCLUDE
element ( INCLUDE_AND_CONTINUE or INCLUDE_AND_PRUNE ). Similarly, to contin-
ue the traversal down the same path, all evaluators must return a CONTINUE evaluator
( INCLUDE_AND_CONTINUE or EXCLUDE_AND_CONTINUE ).
If you run the improved application on the same data set, you'll see the expected output as
before:
Found movie: Alien
Found movie: Heat
This time, however, you used the more fluent Neo4j Traversal API and managed to imple-
ment a solution in a more expressive manner. The Neo4j Traversal API has a declarative
nature: you simply declare how you want the traverser to behave, and start it doing its job.
If you're using the Java API, we recommend you use the Neo4j Traverser Framework API
for graph traversals whenever possible, as it allows you to produce readable, maintainable,
and performant code when dealing with complex graph traversals.
Search WWH ::




Custom Search