匹配筛选返回意外结果Neo4j

ruyhziif  于 2022-10-01  发布在  其他
关注(0)|答案(1)|浏览(111)

我从Neo4j开始,我正在上GraphAcademy中级密码课程。

使用案例是找出在英国发行的电影的数量。

问题是,如果我用where 'UK' in m.countries过滤掉国家列表中没有UK的电影,我会得到不同的英国数量,如果我省略过滤器,我会得到893对1386。

MATCH (m:Movie)                          // get all movie nodes
//where 'UK' in m.countries              // filter out those not released in the UK 
unwind m.countries as countries          // extract countries into separate rows
with m, trim(countries) as country       // trim out unwanted spaces 
with country, collect(m.title) as movies // regroup movies into a list

return country, movies, size(movies)     // return country, list, movie count

无论我是否使用筛选器,我都希望获得相同的英国电影列表,而我希望其他国家的电影列表不同。如果使用筛选器,则不会检索国家/地区列表中没有UK的节点。

如果一部电影没有英国在国家名单中,那么无论如何都不应该被包括在英国电影名单中,对吗?

50pmv0ei

50pmv0ei1#

正是因为这些数据,一些电影包含了作为国家的UK,还有一些电影包含了作为国家的UK。这就是结果不同的原因。试试这个:

MATCH (m:Movie)                       
where 'UK' in m.countries OR ' UK' in m.countries               
unwind m.countries as countries          
with m, trim(countries) as country 
with country, collect(DISTINCT m.title) as movies
return country, size(movies)

现在,无论有没有过滤器,UK都应该得到相同的计数。

相关问题