I changed the query to a query such as the one below (I tested that it works):
MATCH (me:User{id:'220'})-[r:RATED]-(m)
WITH me, avg(r.rating) AS average
MATCH (me)-[r1:RATED]->(m:Movie)<-[r2:RATED]-(other:User)-[r3:RATED]->(m2:Movie)
WHERE r1.rating > average AND r2.rating > average AND r3.rating > average AND NOT (me)-[:RATED]->(m2)
RETURN distinct m2 AS recommended_movie, count(*) AS score
ORDER BY score DESC
LIMIT 15
When I run the query in the browser I get a result that has two columns; recommended movie and score. I would like my query in Java to return the list of recommended movies. However, the hello world example only uses:
return result.single().get(0).asString();
How can I modify this such that I get the list of recommended movies?
WITH distinct m2 AS recommended_movie, count(*) AS score
WITH recommended_movie, score ORDER BY score DESC
RETURN COLLECT(recommended_movie) as movies, COLLECT(score) as scores
You can approach it in two ways. You can either return a list from the query and retrieve the list in the java client, or return a rows and create the list in the java client.
Option 1:
First, alter the query to return a list of movies. You can do this by replacing the current ‘return’ line with the following:
RETURN collect(distinct m2) AS recommended_movies
Next, change your 'return' statement to the following: