Cypher is the query language of Neo4j, and as promised I’ll show you how you can use it to implement friend recommendations as well as degrees of separation.
We can send any cypher query to Neo4j via the REST API and neography using the execute_query command. Let’s implement suggestions_for so it sends a cypher query to the server:
def suggestions_for(node) node_id = node["self"].split('/').last.to_i @neo.execute_query("START me = node({node_id}) MATCH (me)-[:friends]->(friend)-[:friends]->(foaf) RETURN foaf.name", {:node_id => node_id})["data"] end puts "Johnathan should become friends with #{suggestions_for(johnathan).join(', ')}" # RESULT # Johnathan should become friends with Mary, Phil