简体   繁体   English

Cypher 查询 Neo4J

[英]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.我对 Neo4j 非常陌生,所以需要一些帮助现在发布在 ['covid19','china_flu','coronavirus'] 子版块上。 This syntax is not working u.username IN {match (c:User)此语法不起作用 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.我认为 WHERE IN 子句只接受列表,不接受子查询。 I rewrote your query as this and it parses correctly on Neo4j 4.0.3我重写了您的查询,它在 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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