Database Reference
In-Depth Information
g.query ().has("friends of",EQUAL,
"vivek")..has("group",EQUAL,"graphDB").vertices();
This query is a label-indexed query, which searches all of Vivek's friends using
“friends of” and then searches the remaining subset for graphDB using the “group” in-
dexed edge.
We will explore this further in next section of this chapter.
Faster Deep Traversal
Deep traversal means going to the n'th level in the hierarchy of a graph. Let's take the
example we saw in the preceding section of my LinkedIn social graph, where I can
query my
connections
for common group interests. Depending on the data volume and
number of incident edges, iterating over each vertex via vertex query is probably not a
good idea. Titan provides support for multiple-vertex queries, where multiple-vertex
queries can be combined and send a single combined query to a graph database. That
way retrieval of data will be a lot faster because we will be hitting the server only one
time.
Let's explore how to achieve faster deep traversal using a multiple-vertex query in
Titan with a Hindu mythological epic called Ramayana. In this example we will try to
find
son of
relationships at the leaf level.
Figure 7-22
shows the family tree of Rama
and their ancestors.
Figure 7-22
.
The Ramayan family graph
One way to find
son of
relationships at each level is to iterate through each level
like this:
private static void iterateToLeaf(Vertex dasratha)
{