Created
May 11, 2020 21:47
-
-
Save jeanmidevacc/132f605ea76c2a07a9496be791fb7303 to your computer and use it in GitHub Desktop.
neo4j_recommendations_fof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_recommendations_fof(user_id, relationship = 'IS_FRIEND_WITH'): | |
query = f""" | |
MATCH (u:User)-[:{relationship}]->(u1:User)-[:{relationship}]->(u2:User) | |
WHERE u.id = '{user_id}' | |
RETURN collect(DISTINCT u2.id) AS recommendations | |
""" | |
with driver.session() as session: | |
result = session.run(query) | |
return result.values()[0][0] | |
recommendations = get_recommendations_fof('user_id', 'FOLLOWS') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment