-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neo4j-queries.txt
99 lines (65 loc) · 2.54 KB
/
Neo4j-queries.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///users.csv' AS row
FIELDTERMINATOR '|'
CREATE (:Users {userId: row.userId});
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///movies.csv' AS row
FIELDTERMINATOR '|'
CREATE (:Movies {movieId: row.movieId, title: row.title, rating_mean: row.rating_mean});
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///genres.csv' AS row
FIELDTERMINATOR '|'
CREATE (:Genres {genres: row.genres});
CREATE INDEX ON :Users(userId);
CREATE INDEX ON :Movies(movieId);
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///users_movies.csv' AS row
FIELDTERMINATOR '|'
MATCH (user:Users {userId: row.userId})
MATCH (movie:Movies {movieId: row.movieId})
MERGE (user)-[:WATCHED {rating: row.rating}]->(movie);
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///users_genres.csv' AS row
FIELDTERMINATOR '|'
MATCH (user:Users {userId: row.userId})
MATCH (genres:Genres {genres: row.genre})
MERGE (user)-[:FAVORITE]->(genres);
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///movies_genres.csv' AS row
FIELDTERMINATOR '|'
MATCH (movie:Movies {movieId: row.movieId})
MATCH (genres:Genres {genres: row.genres})
MERGE (movie)-[:GENRES]->(genres);
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///movies_similarity.csv' AS row
FIELDTERMINATOR '|'
MATCH (movie1:Movies {movieId: row.movieId})
MATCH (movie2:Movies {movieId: row.sim_movieId})
MERGE (movie1)-[:SIMILAR {relevance: row.relevance}]->(movie2);
[
MATCH path = (u:Users)-[:WATCHED]->(m1:Movies)
WHERE u.userId =~'4'
RETURN u.userId, m1.title, m1.rating_mean
MATCH path = (u:Users)-[:FAVORITE]->(g:Genres)
WHERE u.userId =~'4'
RETURN u.userId, g.genres
MATCH path = (u:Users)-[:WATCHED]->(m1:Movies)-[s:SIMILAR]->(m2:Movies)
WHERE u.userId =~'4'
RETURN u.userId, m1.title, m2.title, m2.rating_mean
MATCH path = (u:Users)-[:WATCHED]->(m1:Movies)-[s:SIMILAR]->(m2:Movies),
(m2)-[:GENRES]->(g:Genres),
(u)-[:FAVORITE]->(g)
WHERE u.userId =~'4'
RETURN u.userId, g.genres, m1.title, m2.title, m2.rating_mean
]
MATCH (u1:Users)-[:WATCHED]->(m3:Movies)
WHERE u1.userId =~'4'
WITH [i in m3.movieId | i] as movies
MATCH path = (u:Users)-[:WATCHED]->(m1:Movies)-[s:SIMILAR]->(m2:Movies),
(m2)-[:GENRES]->(g:Genres),
(u)-[:FAVORITE]->(g)
WHERE u.userId =~'4' and not m2.movieId in movies
RETURN distinct u.userId as userId, g.genres as genres,
m2.title as title, m2.rating_mean as rating
ORDER BY m2.rating_mean descending
LIMIT 5