简体   繁体   中英

Cypher query Neo4J

I am very new to Neo4j so need some assistance I am trying to to execute following query in NeO4j The idea is extract all the users who used to post on ['collapse','science','politics'] subreddits before 01 Jan 2020 and are now posting on ['covid19','china_flu','coronavirus'] subreddits. This syntax is not working u.username IN {match (c:User)

Query

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 

Any assistance will be much appreciated

I think WHERE IN clauses only accept lists, not subqueries. I rewrote your query as this and it parses correctly on 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM