简体   繁体   English

cypher:如何返回不同的关系类型?

[英]cypher: how to return distinct relationship types?

How to return the distinct relationship types from all paths in cypher ? 如何从cypher所有路径返回不同的关系类型?

Example query: 示例查询:

MATCH p=(a:Philosopher)-[*]->(b:SchoolType)
RETURN DISTINCT EXTRACT( r in RELATIONSHIPS(p)| type(r) ) as RelationshipTypes

This returns a collection for each path p. 这将返回每个路径p的集合。

I would like to return a single collection contain the distinct relationship types across all collections. 我想返回一个包含所有集合中不同关系类型的集合。

Here is a link to a graph gist to run the query- 以下是运行查询的图表要点的链接 -

http://gist.neo4j.org/?7851642 http://gist.neo4j.org/?7851642

You might first collect all relationships on the matched path to a collection "allr", and then get the collection of distinct type(r) from the collection of all relationships, 您可能首先将匹配路径上的所有关系收集到集合“allr”,然后从所有关系的集合中获取不同类型(r)的集合,

MATCH p=(a:Philosopher)-[rel*]->(b:SchoolType) 
WITH collect(rel) AS allr 
RETURN Reduce(allDistR =[], rcol IN allr | 
              reduce(distR = allDistR, r IN rcol | 
                     distR +  CASE WHEN type(r) IN distR  THEN []  ELSE type(r) END 
                    )
              )

Note, each element 'rcol' in the collection "allr" is in turn a collection of relationships on each matched path. 注意,集合“allr”中的每个元素'rcol'又是每个匹配路径上的关系集合

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

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