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

lan*_*.io 8 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 =
Run Code Online (Sandbox Code Playgroud)

Nic*_*ite 10

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

节点,关系,路径

MATCH (n) RETURN n;

n是一个Node.

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

r是一个Relationship.

MATCH p = ()-[]-()

p是一个Path.

集合

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

c是一个Collection<Node>.

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

c是一个Collection<Relationship>.

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

c是一个Collection<Path>.

可变长度路径

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

p是一个Path.

r是一个Collection<Relationship>.

并参考您的具体示例:

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

p是一个Path.

a是一个Node.

sp1是一个Collection<Relationship>.

b是一个Node.

sp12是一个Relationship.

c是一个Node.

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

  • 这是我在一段时间内看到的有关Cypher的最佳问题和答案.但只是让@stackoverflowwww知道还有一些未解之谜,并参考有关比较的问题,请查看[此控制台](http://console.neo4j.org/r/gvttx9),默认图表和最低限度修改的查询. (2认同)