简体   繁体   English

Neo4j Cypher RETURN 与模式理解中的 OPTIONAL MATCH

[英]Neo4j Cypher RETURN with OPTIONAL MATCH in pattern comprehensions

I use the following Neo4j Cypher RETURN statement with pattern comprehensions:我使用以下带有模式理解的 Neo4j Cypher RETURN语句:

[ (c1)<-[vg1:HAS_VOTE_ON]-(childD) | {criterion: c1, relationship: vg1} ] AS weightedCriteria

which works fine.效果很好。

I'd like to extend it a little bit to return more information, to something like this:我想将其扩展一点以返回更多信息,如下所示:

[ (c1)<-[vg1:HAS_VOTE_ON]-(childD) WITH c1, vg1 
    OPTIONAL MATCH (c1)-[rc1t:CONTAINS]->(c1t:Translation {deleted: false}) 
    WHERE ($iso6391 IS NOT null AND c1t.iso6391 = $iso6391) | {criterion: c1, relationship: vg1, translation: c1t} ] AS weightedCriteria

but such a query fails with org.neo4j.ogm.exception.CypherException: Cypher execution failed with code 'Neo.ClientError.Statement.SyntaxError on WITH但是这样的查询因org.neo4j.ogm.exception.CypherException: Cypher execution failed with code 'Neo.ClientError.Statement.SyntaxError on WITH

Is it possible to implement with pattern comprehensions?是否可以使用模式理解来实现?

Since pattern comprehension is a form of a subquery, you can use complete subquery syntax to achieve what you want.由于模式理解是子查询的一种形式,您可以使用完整的子查询语法来实现您想要的。

Here, I am assuming you started with c1在这里,我假设您从c1开始

CALL {
  WITH c1
  MATCH (c1)<-[vg1:HAS_VOTE_ON]-(childD) 
  WITH c1, vg1 
  OPTIONAL MATCH (c1)-[rc1t:CONTAINS]->(c1t:Translation {deleted: false}) 
  WHERE ($iso6391 IS NOT null AND c1t.iso6391 = $iso6391)
  RETURN {criterion: c1, relationship: vg1, translation: c1t}
}

Pattern comprehension is like a for loop but simplified and compact form.模式理解就像一个 for 循环,但形式简单紧凑。 So you cannot put another MATCH inside of it.所以你不能在里面放另一个 MATCH。 Try below query and let us know if it works or not.试试下面的查询,让我们知道它是否有效。

MATCH (c1)<-[vg1:HAS_VOTE_ON]-(childD)  
OPTIONAL MATCH (c1)-[rc1t:CONTAINS]->(c1t:Translation {deleted: false}) 
WHERE $iso6391 IS NOT null AND c1t.iso6391 = $iso6391
RETURN collect({criterion: c1, relationship: vg1, translation: c1t}) AS weightedCriteria

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

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