简体   繁体   English

如何使用neo4j密码匹配路径,并在不存在一部分的情况下返回其余部分

[英]How to match a path using neo4j cypher and in case part of it doesn't exist return the rest

I have a Neo4j graph that looks something like this : (person:Person)-[:acted_in]->(movie:Movie)-[:played_in]->(country:Country) 我有一个Neo4j图,看起来像这样:(person:Person)-[:acted_in]->(movie:Movie)-[:played_in]->(country:Country)

I would like to match the whole path using this query: 我想使用此查询匹配整个路径:

MATCH path = ((person:Person)-[:acted_in]->(movie:Movie)-[:played_in]->(country:Country)) RETURN NODES(path), RELATIONSHIPS(path)

but, here is the tricky part, I would also like to add a condition that if [:played_in] does not exist, just return the partial path: (person:Person)-[:acted_in]->(movie:Movie) 但是,这是棘手的部分,我还要添加一个条件,如果[:played_in]不存在,则只需返回部分路径:(person:Person)-[:acted_in]->(movie:Movie)

Thanks. 谢谢。

Maybe something like the following query will be useful for you : 也许类似以下查询的内容对您有用:

MATCH path = (a)-[:b]->(c) 
OPTIONAL MATCH path2 =(c)-[:d]->(e) 
RETURN 
   NODES(path)+COALESCE (NODES(path2),[]), 
   RELATIONSHIPS(path)+COALESCE (RELATIONSHIPS(path2),[])

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

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