Neo4j,如何以所有关系分页节点

时间:2016-07-12 20:36:56

标签: neo4j cypher

我需要从neo4j中读取一些数据用于前端可视化。我需要一次读取10个节点,以及它们之间的所有关系。我尝试了一些查询,但都没有。>

match (p:Page{domain:"www.google.com"})-[r:LinkTo]-(:Page)
with p,r skip 10 limit 10
return collect(distinct p) as pages, collect(distinct r) as links;

这个会给我10个节点和10个关系,但这些节点之间的关系数量大于10。 任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

// 1) Collect pages:
match (P1:Page{domain:"www.google.com"})-[:LinkTo]-(P2:Page)
with P1, P2 limit 10
with collect(distinct P1) + collect(distinct P2) as tmp
unwind tmp as p
with collect(distinct p) as pages

// 2) Then get a Cartesian product:    
unwind pages as P1
  unwind pages as P2
  optional match (P1)-[r:LinkTo]-(P2)
RETURN pages, collect(distinct r) as links

如果您需要最多10个节点:

 // 1) Collect pages:
MATCH (P1:Page{domain:"www.google.com"})-[:LinkTo]-(P2:Page)
WITH P1, P2 LIMIT 10
WITH collect(distinct P1) + collect(distinct P2) as CP
UNWIND CP  as P
WITH distinct P LIMIT 10
WITH collect(P) as pages

// 2) Then get a Cartesian product:    
unwind pages as P1
  unwind pages as P2
  optional match (P1)-[r:LinkTo]-(P2)
RETURN pages, collect(distinct r) as links