Database Reference
In-Depth Information
Next you repeat the same process for the incoming direction of the bidirectional traversal,
using the same traversal description , but note that there's nothing stopping you from
using a different traversal in the incoming direction (for example, by following different
relationships).
The next step is to configure the collision evaluator . The collision evaluator is the reg-
ular Evaluator implementation, which is used to determine what should happen when
incoming and outgoing traversals collide. You want to return all such collisions, so your
evaluator simply returns Evaluation.INCLUDE_AND_CONTINUE .
The last step in building the BidirectionalTraversalDecription is setting the
side selector , responsible for determining how traversals from both sides progress.
You provide the built-in ALTERNATING side selector, which, as its name states, alternates
between traversal directions (one step in one direction, and one step in the opposite direc-
tion).
With that, your bidirectional traversal is ready, so you can kick it off by calling the tra-
verse method and specifying the starting and ending nodes
. As usual, you iterate
through the results until you exhaust the traversal
.
Whatbenefitdoyougetfromusingbidirectionaltraversal?Aswementionedbefore,doing
a standard, one-direction traversal on a large graph can have less-than-optimal perform-
ance. By using a bidirectional traversal in such scenarios, you effectively employ two tra-
versals to walk the graph, splitting the size of the problem in half. With typical one-dir-
ectional traversal, the number of relationships traversed increases exponentially with the
depth of the traversal. When using bidirectional traversal, each side of the traversal will
havetovisithalfofthegraphdepth,resultinginfewernode-relationship-nodehopstoper-
form, in turn resulting in much better performance.
Note
Built-in graph algorithms available in Neo4j, such as shortestPath or a* graph
searches (from the GraphAlgoFactory class), use bidirectional traversal starting with
Neo4j version 1.8.
Search WWH ::




Custom Search