[英]Having multiple OPTIONAL MATCH in Cypher
I'm looking to form a query what should match on at least one of the OPTIONAL MATCH.我希望形成一个查询,应该匹配至少一个OPTIONAL MATCH。 In this form it would return a result even when none of the OPTIONAL MATCH, which is not what I desire.
在这种形式中,即使没有OPTIONAL MATCH ,它也会返回结果,这不是我想要的。
MATCH (media:Media)-[rr:HAS]-(ad:Ad) OPTIONAL MATCH (media)--(word:Word) WHERE word.value IN ['thing'] OPTIONAL MATCH (media) WHERE media.description CONTAINS 'something' RETURN media, collect(DISTINCT word) as word, collect(DISTINCT ad) as ad
UNION
would be a better fit in this case. UNION
更适合这种情况。 The only caveat is that you return columns with the same alias from each part of the union.唯一的警告是您从联合的每个部分返回具有相同别名的列。
MATCH (media:Media)-[rr:HAS]-(ad:Ad)
MATCH (media)--(word:Word) WHERE word.value IN ['thing']
RETURN media, collect(DISTINCT word) as things
UNION
MATCH (media:Media)-[rr:HAS]-(ad:Ad)
MATCH (media) WHERE media.description CONTAINS 'something'
RETURN media, collect(DISTINCT ad) as things
This would produce zero results if neither part matches, and at least one if either matches.如果两个部分都不匹配,这将产生零结果,如果任何一个匹配,则至少产生一个结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.