Database Reference
In-Depth Information
The only difference in the code is the different constant used to configure the uniqueness:
.
NODE_PATH
If you run this query, the output will look like this:
John
John
John is printed twice—you have two entries in your result, although both represent the
same node. Why did this happen? Take a careful look at the graph in
figure 8.5
. Jane
is indeed connected to Ben via John. But there is another path that connects Jane and
Ben—one via Kate and John! These are different paths in the graph, and because you're
using
NODE_PATH
uniqueness, both represent valid results.
Previously, you only had one result because both paths (Jane-John-Ben and
Jane-Kate-John-Ben) go via the
john
node, and since you used
NODE_GLOBAL
unique-
ness, the second path was never realized.
To illustrate this further, let's change the traversal query slightly, and find what paths Jane
has to Ben via her direct contacts.
To answer this, you must understand that you're not only interested in the users who know
Ben, but rather in all nodes on paths between Jane and Ben. All you have to do is change
the result of your traversal, as the next snippet shows: