Databases Reference
In-Depth Information
+--------------------------------------------------+
| name | score | interests | distance |
+--------------------------------------------------+
| "Arnold" | 2 | ["Travel","Java"] | 2 |
| "Charlie" | 1 | ["Medicine"] | 1 |
+--------------------------------------------------+
2 rows
Note that the results are ordered by
score
, not
distance
. Arnold has two out of the
three interests, and therefore scores higher than Charlie, who only has one, even though
he is at two removes from Sarah, whereas Charlie has worked directly with Sarah.
Figure 5-5
shows the portion of the graph that was traversed and matched to generate
these results.
Figure 5-5. Finding people with particular interests
Let's take a moment to understand how this query executes in more detail.
Figure 5-6
shows three stages in the execution of the query. The first stage shows each of the paths
as they are matched by the
MATCH
and
WHERE
clauses. As we can see, there is one redunā
dant path:
Charlie
is matched directly, through
Next Gen Platform
, but also indirectly,
by way of
Quantum Leap
and
Emily
. The second stage represents the filtering that takes
place in the
WITH
clause. Here we emit triples comprising the matched person, the
matched interest, and the length of the shortest path from the subject through the
matched person to her interest. The third stage represents the
RETURN
clause, wherein