Database Reference
In-Depth Information
complex the graph, the more nodes you have to remember, resulting in a larger memory
footprint.
In general, the more relationships there are per node, the more memory is needed for
breadth-first traversal.
How do you choose between depth-first and breadth-first ordering? You have to realize
that you, as an application architect and developer, have one big advantage: you know and
understand the domain model you operate on. Based on your domain insight, you can de-
termine which ordering to use for each of your traversals (and it can vary from case to case
on the same graph).
If the solution is close to the starting node, breadth-first ordering would probably be better.
But if the graph is very dense (that is, has a lot of relationships per node), breadth-first or-
dering may use too much memory to be practical.
An understanding of traversal ordering and insight into your problem domain will give
you a good starting point, but to determine the best traversal overall, you'll need to ex-
periment with different options. If Neo4j's built-in ordering options don't match your
requirements, you can implement your own ordering by using the
org.neo4j.graphdb.traversal.BranchSelector interface, which is part of
the Neo4j Traversal API. Custom traversal implementations are out of scope for this topic,
butyoucanfindusefulinformationbylookingattheNeo4jManual( http://docs.neo4j.org/ )
and visiting the Neo4j Google Groups ( https://groups.google.com/forum/#!forum/neo4j ) .
Let's look at the Neo4j mechanisms that can help you decide how to follow relationships
from the current node during traversal: path expanders.
8.2. Expanding relationships
The expander is the component of the Neo4j Traversal API that's responsible for deciding
which relationships should be followed from any node visited during the traversal. Inaddi-
tion to selecting relationship types and directions, the expander is responsible for the order
in which relationships are followed.
Search WWH ::




Custom Search