Database Reference
In-Depth Information
Listing 8.3. Finding all movies John's friends and colleagues like
You use the TraversalDescription.expand(...) method to set the expander
you want to use for the traversal
. You instantiate StandardExpander using the
static factory method, then add the relationships you'd like to follow . Because you're
looking at movies that John's direct contacts have seen, you want to include only nodes
at depth 2 and stop the traversal after that . To make sure you're only returning movie
nodes in the result (and not user nodes, for example), you add another evaluator to check
the title property on the nodes, because only movie nodes have this property . Fin-
ally,youexecutethetraversalstartingfromthenoderepresentingJohn,andprintthemovie
titles to the console
.
Once the query is executed, the expected result is printed to the console:
Fargo
Alien
In the code, you passed the expander built into the StandardExpander class to the
TraversalDescription.expand(...) method to select which relationships to
follow from each node. But because StandardExpander is the default expander used
by the TraversalDescription builder, you can conveniently use its shortcut meth-
 
Search WWH ::




Custom Search