Database Reference
In-Depth Information
You can also provide the uniqueness filter, which ensures uniqueness among the visited
nodes/paths. For example, trvDesc.uniqueness(Uniqueness.NODE_GLOBAL)
defines that a node should not be visited more than once during the traversing process.
We can also filter on the relationships and its direction. For example, we can add the fol-
lowing piece of code in Traversals.java for applying filters on relationships.
Add an Enum in Traversals.java :
public enum RelTypes implements RelationshipType {
ACTED_IN, DIRECTED
}
Then add the following code as the fourth rule for our traversal descriptor:
trvDesc.relationships(RelTypes.ACTED_IN, Direction.BOTH);
Note
Refer to org.neo4j.graphdb.traversal .Evaluators at http://neo4j.com/docs/
2.1.5/javadocs/org/neo4j/graphdb/traversal/Evaluators.html for understanding the various
rules provided by Neo4j.
After defining the rules, we get the instance of traverser from the TravesalDescrip-
tion by providing a starting node and then we start traversing the graph. The instances
of traverser are lazy loading, so it's performant even when we are dealing with thousands
of nodes, that is, they will not start traversing or scanning until we start iterating over it.
Apart from traversals, Neo4j also provides a graph algorithm factory
org.neo4j.graphalgo . GraphAlgoFactory that exposes the following prebuilt
graph algorithms:
GraphAlgoFactory.shortestPath(…) : This returns the algorithm that
finds the shortest path between two given nodes
GraphAlgoFactory.allPaths(…) : This returns the algorithm that finds
all the possible paths between two given nodes
GraphAlgoFactory.allSimplePaths(…) : This returns the algorithm
that finds all simple paths of a certain length between the given nodes
GraphAlgoFactory.dijkstra(…) : This returns the algorithm that finds
the path with the lowest cost between two given nodes
Search WWH ::




Custom Search