试图理解MATCH和WHERE中的标识符和集合

时间:2015-11-11 17:04:16

标签: neo4j cypher

我试图理解某些标识符或表达式对应于什么类型的密码“数据结构”,具体取决于它们的使用方式和位置。 下面我列出了我遇到的例子。请告诉我,如果我做对了(在评论中)或我错过了什么。

MATCH (a:MYTYPE { label:'l_a' })
// a corresponds to a collection of nodes

MATCH (b:MYTYPE { label:'l_b' })
// so does b

MATCH p=(a)-[sp1:CF*]->(b)-[sp12:CF]->(c)
// p corresponds to a collection of paths
// a and b correspond to a collection of nodes 
// (or does the previous MATCH of a and b change something?)
// sp1 corresponds to a collection of collections of relationships
// sp12 corresponds to a collection of relationships
// c corresponds to a collection of nodes

WHERE ( p = ... )
// Here, the p corresponds to a path, i.e. there must be a path or (I don't know) on the right side of the =
WHERE ( a = ... )
// a corresponds to a node, i.e. there must be a node on the right side of the =
WHERE ( sp1 = ... )
// sp1 corresponds to a collection of nodes, i.e. there must be a collection of relationships on the right side

//BONUS:
WHERE ( (e)-[sp2:CF*]->(f) ) = ...
// there must be a collection of collections of paths on the right side of the =

1 个答案:

答案 0 :(得分:10)

我认为回答所有这些问题的最简单方法是将标识符传递给函数,这些函数会抛出一个错误,告诉您它的预期和实际收到的内容。我认为你也应该小心你如何使用单词集合,因为它不正确。

节点,关系,路径

MATCH (n) RETURN n;

nNode

MATCH ()-[r]-() RETURN r;

rRelationship

MATCH p = ()-[]-()

pPath

集合

MATCH (n) WITH COLLECT(n) AS c RETURN c;

cCollection<Node>

MATCH ()-[r]-() WITH COLLECT(r) AS c RETURN c;

cCollection<Relationship>

MATCH p = ()-[]-() WITH COLLECT(p) AS c RETURN c;

cCollection<Path>

可变长度路径

MATCH p = ()-[r*..2]-() RETURN p, r;

pPath

rCollection<Relationship>

并参考您的具体示例:

MATCH p = (a)-[sp1:CF*]->(b)-[sp12:CF]->(c)

pPath

aNode

sp1Collection<Relationship>

bNode

sp12Relationship

cNode

而且我不确定你对WHERE条款的要求。也许你可以通过编辑你的问题来澄清。