Database Reference
In-Depth Information
Neo4j provides a rich Traversal API, which you can employ to navigate through the graph.
In addition, you can use the REST API or Neo4j query languages to traverse your data.
We'll dedicate much of this topic to teaching you the principles of and best practices for
traversing data with Neo4j.
To get all the friends of a user's friends, run the code in the following listing.
Listing 1.2. Neo4j Traversal API code for finding all friends at depth 2
TraversalDescription traversalDescription =
Traversal.description()
.relationships("IS_FRIEND_OF", Direction.OUTGOING)
.evaluator(Evaluators.atDepth(2))
.uniqueness(Uniqueness.NODE_GLOBAL);
Iterable<Node> nodes = traversalDescription.traverse(nodeById).nodes();
Don't worry if you don't understand the syntax of the code snippet in listing
1.2 —everything will be explained slowly and thoroughly in the next few chapters. Figure
1.3 illustrates the traversal of the social network graph, based on the preceding traversal
description.
 
Search WWH ::




Custom Search