Boosting Recommendation Results
The query below finds the recommended friends for the origin that are working at the same place as the origin (in this example, Clark Kent
).
The recommended friend knows a person that the origin knows and doesn’t already know the origin.
MATCH (origin)-[r1:KNOWS|WORKS_AT]-(c)-[r2:KNOWS|WORKS_AT]-(candidate)
WHERE origin.name = "Clark Kent"
AND type(r1)=type(r2) AND NOT (origin)-[:KNOWS]-(candidate)
RETURN origin.name AS origin, candidate.name AS candidate, collect(r2.activity) AS activity, collect(r2.weight) AS weight
This recommendation is weighted for the weight of the relationship r2
, and boosted with a factor of 2, if there is an activity
-property on that relationship.
MATCH (origin)-[r1:KNOWS|WORKS_AT]-(c)-[r2:KNOWS|WORKS_AT]-(candidate)
WHERE origin.name = "Clark Kent"
AND type(r1)=type(r2) AND NOT (origin)-[:KNOWS]-(candidate)
RETURN origin.name AS origin, candidate.name AS candidate,
SUM(ROUND(r2.weight + (COALESCE(r2.activity, 0) * 2))) AS boost
ORDER BY boost DESC LIMIT 10
This returns the recommended friends for the origin nodes and their recommendation score.
Is this page helpful?