I have a database with some movies. The movies are released in regions with a hierarchy. The hierarchy is like this (Global)-[contains]->(EU), (Global)-[contain]->(US), (EU)-[contains]->(UK), (EU)-[contains]->(SE).
I want a Cypher query that will return releases of movies in my region, or one of the regions higher up in the hierarchy.
If I am in the UK and a movie is released in the UK and in the EU, I want to return only the UK release. If it's released in EU, but does not have a specific UK release, I want to return the EU release.
The problem is how do I avoid duplicates.
My data has a structure like this and I want to return a single release for each movie
(Movie1)-[has_release]->(release1)-[has_region]->(EU)
(Movie1)-[has_release]->(release2)-[has_region]->(Global)
(Movie2)-[has_release]->(release3)-[has_region]->(UK)
(Movie2)-[has_release]->(release4)-[has_region]->(US)
In this case, when I do a query for movies in the UK, I want to return release1 (and release3), because EU has a contains relationship to UK, but I don't want to return release2, because it has already found a release for Movie1, so I want to return the release which is closest in the region hierarchy to UK, in this case EU.