Database Reference
In-Depth Information
Graph traversals
Neo4j provides a callback API for traversing the graph based on certain rules provided by
the users. Basically, users can define an approach to search a graph or subgraph, which de-
pends upon certain rules/algorithms such as depth-first or breadth-first.
Let's understand a few concepts of traversing:
Path expanders : This defines what to traverse in terms of relationship direction
and type
Order of search : The types of search operations are depth-first or breadth-first
Evaluator : This decides whether to return, stop, or continue after a certain point in
traversal
Starting nodes : This is the point from where the traversal will begin
Uniqueness : This visits the nodes (relationships and paths) only once
Let's continue our Movie dataset, which we created in Chapter 3 , Pattern Matching in
Neo4j , and create a Java-based traverser for traversing the graph:
import org.neo4j.cypher.ExecutionEngine;
import org.neo4j.cypher.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.kernel.impl.util.StringLogger;
import scala.collection.Iterator;
public class Traversals {
//This should contain the path of your Neo4j Datbase which
is
//generally found at <$NEO4J_HOME>/data/graph.db
Search WWH ::




Custom Search