Database Reference
In-Depth Information
Listing 4.6. Using the Neo4j Traversal API to find movies seen by friends
Neo4j provides a default implementation of the TraversalDescription interface,
which
you
can
instantiate
using
the
static
factory
method
Traversal.description() . This will typically be your starting point when
building a TraversalDescription , as you'll rarely need to provide your own im-
plementation. Next, you define the relationships you want to include in the traversal
, . TraversalDescription maintains the list of relationships added using the
TraversalDescription.relationships(...) method, and only relationships
that this list contains will be followed by the traverser. You can add the relationship type
without specifying a direction, in which case both directions will be allowed
, or you
can specify the allowed direction relative to the starting node
.
Inthe next line youspecify howthe traverser should behave with respect tothe uniqueness
of the nodes and relationships it encounters during the traversal. You want each node to be
visited exactly once, so you set uniqueness to Uniqueness.NODE_GLOBAL . Oth-
er allowed values are, for example, Uniqueness.NODE_PATH , which allows multiple
traversals through the same node while the path from the starting node to the current node
is unique; or Uniqueness.RELATIONSHIP_GLOBAL , which allows traversal through
each relationship only once. We'll explain the differences between uniqueness values in
more detail in chapter 8 .
 
Search WWH ::




Custom Search