Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

unique genres: Intermediate Cypher Queries

I wanted to make a variant of the exercise and verify automatically which are the unique genres . This is my solution:
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL
WITH n {
  actors: [ (n)<-[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ],
  genres: [ (n)-[:IN_GENRE]->(g) | g {.name}]
ORDER BY n.imdbRating DESC
RETURN collect(n) as listOfFilms
  with listOfFilms
  unwind listOfFilms as x
  with uniquegen = [genx{.name} in x.genres where 
    unwind listOfFilms as y
    isEmpty([geny{.name} in y.genres  where x<>and ]
return uniquegen
return uniquegen
The second call doesn't work since I get an error for the presence of "where " after x.genres in the definition of the list. There I wanted to use a list comprehension to define a list of genres that are unique: that genre is present in only one movie in the list got from the first call. Why I get that error ? 
The problem is in the second call:
With unwind I get x as iterator for listOfFilm then I build the list uniqueGen doing so: I add genx{.name}  in the list (genx is an element of list x) only if there isn't an other element geny with genx = geny and geny got from list y with y iterator on listOfFilm, as previously, I verify also x<>y otherwise the film could be the same.  


The error is due to your syntax in the second call statement. There is not an assignment operator in the 'with' clause. Instead, you use the 'as' clause to set a value to a variable. 

I didn't know try to fix your query, as it is really a convoluted approach. You can use the following query if you are just interested in the list of unique genres. 

with as genre, count(n) as noOfMovies
where noOfMovies = 1
return genre