|| apoc.path.create - APOC 核心文档 - Neo4j 文档

apoc.path.create

详情

语法

apoc.path.create(startNode [, rels ])

描述

从给定的起始节点关系列表返回一个路径

参数

名称

类型

描述

startNode

NODE

新路径的起始节点。

rels

LIST<RELATIONSHIP>

用于创建路径的关系列表。默认值为:[]

返回

PATH

使用示例

本节中的示例基于以下示例图

MERGE (manUtd:Club {name: 'Man Utd'})
MERGE (juventus:Club {name: 'Juventus'})
MERGE (flamengo:Club {name: 'Flamengo'})

MERGE (premierLeague:League {name: 'Premier League'})
MERGE (serieA:League {name: 'Serie A'})
MERGE (brasileirao:League {name: 'Brasileirão'})

MERGE (england:Country {name: 'England'})
MERGE (brazil:Country {name: 'Brazil'})

MERGE (uefa:Confederation {name: 'UEFA'})

MERGE (manUtd)-[:IN_LEAGUE]->(premierLeague)
MERGE (premierLeague)-[:IN_COUNTRY]->(england)
MERGE (england)-[:IN_CONFEDERATION]->(uefa)

MERGE (juventus)-[:IN_LEAGUE]->(serieA)

MERGE (flamengo)-[:IN_LEAGUE]->(brasileirao)
MERGE (brasileirao)-[:IN_COUNTRY]->(brazil);

apoc.path.create 函数从起始节点和关系列表创建路径。此函数的一个用例是组合来自 OPTIONAL MATCH 子句的关系。

以下查询从 OPTIONAL MATCH 子句返回的关系创建路径

MATCH (club:Club)
OPTIONAL MATCH (club)-[inLeague:IN_LEAGUE]->(league)
OPTIONAL MATCH (league)-[inCountry:IN_COUNTRY]->(country)
OPTIONAL MATCH (country)-[inConfederation:IN_CONFEDERATION]->(confederation)
RETURN club.name, apoc.path.create(club, [inLeague, inCountry, inConfederation]) AS path
ORDER BY length(path);
结果
club.name path

"Juventus"

(:Club {name: "Juventus"})-[:IN_LEAGUE]→(:League {name: "Serie A"})

"Flamengo"

(:Club {name: "Flamengo"})-[:IN_LEAGUE]→(:League {name: "Brasileirão"})-[:IN_COUNTRY]→(:Country {name: "Brazil"})

"Man Utd"

(:Club {name: "Man Utd"})-[:IN_LEAGUE]→(:League {name: "Premier League"})-[:IN_COUNTRY]→(:Country {name: "England"})-[:IN_CONFEDERATION]→(:Confederation {name: "UEFA"})

© . This site is unofficial and not affiliated with Neo4j, Inc.