我有一个大型的Cypher查询,我在其中收集了一些信息,用于我的应用中的视图。在一个部分,我使用OPTIONAL MATCH来获得即将到来的聚会,但我需要他们在进入COLLECT之前通过ASC订购并使用WITH语句向前传递。我试图将它添加到WHERE子句下面,显然,它会抛出一个错误。
有没有办法在OPTIONAL MATCH或COLLECT声明中订购?
这是我的Cypher查询
MATCH (o:Person)<-[:OWNED_BY]-(g:Group {group_slug:"'.$group_slug.'"})<-[:MEMBER_OF]-(m:Person)-[:JOB_TITLE]->(title:Title)
WITH o,g,COLLECT({first_name: m.first_name, last_name: m.last_name, image_name: m.image_name, username: m.username, job_title: title.job_title}) as members,title,COUNT(m) as member_count
OPTIONAL MATCH (g)-[:TOPIC_OF]->(t:Topic)
WITH o,members,g,COLLECT(DISTINCT t.name) as topics,title,member_count
OPTIONAL MATCH (g)-[:CREATED]->(mu:Meetup{status:"Active"})-[:MEETUP_AT]->(l:Location)
WHERE toInt(mu.meet_date) >= '.time().'
WITH o,members,g,title,topics,COLLECT({location_name:l.location_name, address:l.address,city:l.city,state:l.state,zip_code:l.zip_code,meet_date:mu.meet_date,meeting_id:id(mu)}) as meetups,member_count
OPTIONAL MATCH (g)-[]->(amu:Meetup)
WITH o,members,g,title,topics,meetups,COUNT(amu) as meetup_count,member_count
OPTIONAL MATCH (g)<-[:REQUESTED]-(pm:Person)-[:JOB_TITLE]->(pmt:Title)
WITH o,members,g,title,topics,meetups,meetup_count,COLLECT({first_name: pm.first_name, last_name: pm.last_name, image_name: pm.image_name, username: pm.username, job_title: pmt.job_title}) as requested,member_count
OPTIONAL MATCH(g) <-[:FAVORITED]-(fp:Person)
WITH o,members,g,title,topics,meetups,meetup_count,requested,COUNT(fp) as favorited,member_count
RETURN o.username as owner_username, o.first_name as owner_first, o.last_name as owner_last, g.group_name as group_name, g.description as description, g.access as access, g.group_slug as group_slug,
topics, members,meetups,meetup_count, favorited,requested,member_count
违规查询部分
OPTIONAL MATCH (g)-[:CREATED]->(mu:Meetup{status:"Active"})-[:MEETUP_AT]->(l:Location)
WHERE toInt(mu.meet_date) >= time()
答案 0 :(得分:0)
[被修改]
WITH
条款后面可以跟ORDER BY
,SKIP
和LIMIT
条款。
此查询是否适合您?
WITH timestamp() AS now
MATCH (o:Person)<-[:OWNED_BY]-(g:Group {group_slug:"'.$group_slug.'"})<-[:MEMBER_OF]-(m:Person)-[:JOB_TITLE]->(title:Title)
WITH o,g,COLLECT({first_name: m.first_name, last_name: m.last_name, image_name: m.image_name, username: m.username, job_title: title.job_title}) as members,title,COUNT(m) as member_count
OPTIONAL MATCH (g)-[:TOPIC_OF]->(t:Topic)
WITH o,members,g,COLLECT(DISTINCT t.name) as topics,title,member_count
OPTIONAL MATCH (g)-[:CREATED]->(mu:Meetup{status:"Active"})-[:MEETUP_AT]->(l:Location)
WHERE mu.meet_date >= now
WITH o,members,g,topics,title,member_count,mu,l
ORDER BY mu.meet_date
WITH o,members,g,title,topics,COLLECT({location_name:l.location_name, address:l.address,city:l.city,state:l.state,zip_code:l.zip_code,meet_date:mu.meet_date,meeting_id:id(mu)}) as meetups,member_count
OPTIONAL MATCH (g)-[]->(amu:Meetup)
WITH o,members,g,title,topics,meetups,COUNT(amu) as meetup_count,member_count
OPTIONAL MATCH (g)<-[:REQUESTED]-(pm:Person)-[:JOB_TITLE]->(pmt:Title)
WITH o,members,g,title,topics,meetups,meetup_count,COLLECT({first_name: pm.first_name, last_name: pm.last_name, image_name: pm.image_name, username: pm.username, job_title: pmt.job_title}) as requested,member_count
OPTIONAL MATCH(g) <-[:FAVORITED]-(fp:Person)
WITH o,members,g,title,topics,meetups,meetup_count,requested,COUNT(fp) as favorited,member_count
RETURN o.username as owner_username, o.first_name as owner_first, o.last_name as owner_last, g.group_name as group_name, g.description as description, g.access as access, g.group_slug as group_slug,
topics, members,meetups,meetup_count, favorited,requested,member_count;
为了提高效率,我们首先创建一个now
变量,而不是每次需要时重新计算当前时间。这也将确保一致的结果:
WITH timestamp() AS now
&#34;违规&#34;中的WHERE
条款查询部分已被替换为:
WHERE mu.meet_date >= now
WITH o,members,g,topics,title,member_count,mu,l
ORDER BY mu.meet_date