5.2. Basic Friend finding based on social neighborhood

5.2.1. Simple Friend Finder

Imagine an example graph like

Graph

cypher-collabfiltering-graph.svg

5.2.1. Simple Friend Finder

To find out the friends of Joes friends that are not already his friends, Cypher looks like:

Query

START joe=node:node_auto_index(name = "Joe")
MATCH joe-[:knows]->friend-[:knows]->friend_of_friend, joe-[r?:knows]->friend_of_friend
WHERE r IS NULL
RETURN friend_of_friend.name, COUNT(*)
ORDER BY COUNT(*) DESC, friend_of_friend.name

The list of Friends-of-friends order by the number of connections to them, secondly by their name.

Result

friend_of_friend.namecount(*)
3 rows, 11 ms

"Ian"

2

"Derrick"

1

"Jill"

1