简体   繁体   English

Cypher-收集不同匹配子句之间的关系

[英]Cypher - Collecting relationships across different match clauses

I would like to collect relationships from different match clauses as a single column in the results. 我想从不同的匹配子句中收集关系作为结果中的单个列。 To be more specific, I have created an example that corresponds to my use case and can be found here: http://console.neo4j.org/r/3g84gc . 更具体地说,我创建了一个与用例相对应的示例,可以在以下位置找到: http : //console.neo4j.org/r/3g84gc r1, r2 and r3 are relationships from different match clauses. r1,r2和r3是来自不同匹配子句的关系。 There is only one valuation of target where multiple relationships are returned: 只有一种对目标的评估可以返回多个关系:

target = (0:Crew {name:"Neo"}), 
r1 = (0)-[0:KNOWS]->(1), 
r2 = (0)-[1:LOVES]->(2), 
r3 = (1)-[2:KNOWS]->(2). 

What I want is: 我想要的是:

target = (0:Crew {name:"Neo"}), 
rels = (0)-[0:KNOWS]->(1), (0)-[1:LOVES]->(2), (1)-[2:KNOWS]->(2)

I would like to do this WITHOUT having to specify all relationships in the return clause and then manually parse relationship columns. 我想这样做而不必在return子句中指定所有关系,然后手动解析关系列。 It would also be favourable to order valuations of target by the number of relationships found. 通过找到的关系数来订购目标的评估也将是有利的。

Is there a way to do this in Cypher? 有没有办法在Cypher中做到这一点?

If I'm understanding the problem correctly, I think the following RETURN would give you what you want: 如果我正确地理解了问题,那么我认为下面的RETURN将为您提供所需的信息:

RETURN DISTINCT target, [r1,r2,r3]

In the console example that you shared, this returns null values for the second and third positions of the array, but you can fix that, if you want, by changing the OPTIONAL MATCH clauses to MATCH 在您共享控制台例如,这将返回null值阵列的第二和第三位置,但可以解决这个问题,如果需要,通过改变OPTIONAL MATCH子句MATCH

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

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