Databases Reference
In-Depth Information
Running this query against our sample graph, with Sarah as the subject, yields the fol‐
lowing results:
+---------------------------------------+
| name | score | interests |
+---------------------------------------+
| "Ben" | 2 | ["Graphs","REST"] |
| "Charlie" | 1 | ["Graphs"] |
+---------------------------------------+
2 rows
Figure 5-3
shows the portion of the graph that was matched to generate these results.
Figure 5-3. Colleagues who share Sarah's interests
Notice that this query only finds people who work for the same company as Sarah. If
we want to extend the search to find people who work for other companies, we need to
modify the query slightly:
START
subject=
node
:user(name=
{name}
)
MATCH
(subject)-[:INTERESTED_IN]->(interest)<-[:INTERESTED_IN]-(person),
(person)-[:WORKS_FOR]->(company)
RETURN
person.name
AS
name,
company.name
AS
company,
count
(interest)
AS
score,
collect
(interest.name)
AS
interests
ORDER BY
score
DESC
The changes are as follows: