Skip to content

Instantly share code, notes, and snippets.

@jexp
Last active June 14, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/30602ccffd272a78b5fdeb3ed86ed459 to your computer and use it in GitHub Desktop.
Save jexp/30602ccffd272a78b5fdeb3ed86ed459 to your computer and use it in GitHub Desktop.
//Movies based on similar users and favorite genres
MATCH (u:Users)-[:WATCHED]->(m:Movies)
WHERE u.userId ='1'
WITH collect(m) as watchedMovies
MATCH (u:Users)-[:WATCHED]->(m1:Movies)-[s:SIMILAR]->(m2:Movies),
(m2)-[:GENRES]->(g:Genres), (u)-[:FAVORITE]->(g)
WHERE u.userId ='10' and m2 IN watchedMovies
RETURN distinct u.userId as userId, g.genres as genres, m2.title as title, m2.rating_mean as rating
ORDER BY m2.rating_mean DESC LIMIT 10;
// Item-Item Similarity
MATCH (m2:Movies {movieId: "10"})-[:GENRES]->(g:Genres)<-[:GENRES]-(other:Movies)
WITH m2, other, COUNT(g) AS intersection, COLLECT(distinct g.genres) AS genres
MATCH (m2)-[:GENRES]->(m2g:Genres)
WITH m2,other, intersection,genres, COLLECT(m2g.genres) AS s1
MATCH (other)-[:GENRES]->(og:Genres)
WITH m2,other,intersection,genres, s1, COLLECT(og.genres) AS s2
WITH m2,other,intersection,s1,s2
WITH m2,other,intersection,s1+[x IN s2 WHERE NOT x IN s1] AS union, s1, s2
// ... missing bits here ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment