首页 > 解决方案 > 密码查询 Neo4J

问题描述

我对 Neo4j 非常陌生,因此需要一些帮助我正在尝试在 NeO4j 中执行以下查询 这个想法是提取所有在 2020 年 1 月 1 日之前在 ['collapse' ,'science' ,'politics'] 子版块上发帖的用户现在发布在 ['covid19','china_flu','coronavirus'] 子版块上。此语法不起作用 u.username IN {match (c:User)

询问

match (s:Subreddit)--(p:Post)--(u:User) 
where toLower(p.title) =~ '.*corona.*' 
and s.display_name IN ['covid19','china_flu','coronavirus']
and p.created_utc_str >= '2020-01-01'
and p.created_utc_str <= '2020-01-30'
and u.username IN {match (c:User)-[:Submitted]->(b:Post)-[:Submitted]->(t:Subreddit)
                    where t.display_name IN ['collapse' ,'science' ,'politics'] 
                    and p.created_utc_str < '2020-01-01'
                    return distinct c.username}
return distinct  s,p,u
order by p.created_utc_str 

任何帮助将不胜感激

标签: neo4j

解决方案


我认为 WHERE IN 子句只接受列表,不接受子查询。我重写了你的查询,它在 Neo4j 4.0.3 上正确解析

// Collect the distinct users who posted to pre-COVID subreddits into 'cspUsers'    
match (c:User)-[:Submitted]->(b:Post)-[:Submitted]->(t:Subreddit)
                    where t.display_name IN ['collapse' ,'science' ,'politics'] 
                    and b.created_utc_str < '2020-01-01'
with collect(distinct c.username) as cspUsers
// Match users who posted into COVID subreddits who are also in 'cspUsers'
match (s:Subreddit)--(p:Post)--(u:User) 
where toLower(p.title) =~ '.*corona.*' 
and s.display_name IN ['covid19','china_flu','coronavirus']
and p.created_utc_str >= '2020-01-01'
and p.created_utc_str <= '2020-01-30'
and u.username IN cspUsers
return distinct  s,p,u
order by p.created_utc_str

推荐阅读