Database Reference
In-Depth Information
Listing 8.5. Expanding relationships based on distance from the starting node
The DepthAwareExpander implementsthe PathExpander interfacefromtheNeo4j
kernel API
. To map the distance from the starting node (or depth) to the relationship
types, you use a simple java.util.Map
.
The key method to implement is expand(...) , which expands the relationships you
should follow from the node you're currently visiting
. The depth of the currently vis-
ited node can be found with the Path.length() method
. Next, you look up the
relationshipsforthegivendepthfromtheconfiguredmappings
.Finally,youreturnthe
expanded relationships of specified types from the current node
. The current node is
located using the Path.endNode() method.
The next step is to use the custom expander in the actual traversal. The following listing
shows a traversal that prints query results to the console (titles of all movies John's direct
friends like).
Search WWH ::




Custom Search