Prev |  | Next

## 5.5. Basic friend finding based on social neighborhood

Imagine an example graph like the following one:

Figure 5.3. Graph

To find out the friends of Joe’s friends that are not already his friends, the query looks like this:

Query.

    MATCH (joe { name: 'Joe' })-[:knows*2..2]-(friend_of_friend)
    WHERE NOT (joe)-[:knows]-(friend_of_friend)
    RETURN friend_of_friend.name, COUNT(*)
    ORDER BY COUNT(*) DESC , friend_of_friend.name

This returns a list of friends-of-friends ordered by the number of connections to them, and secondly by their name.

Result

friend_of_friend.name | COUNT(*)
--- | ---
3 rows
`"Ian"` | `2`
`"Derrick"` | `1`
`"Jill"` | `1`

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |