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

apoc.path.combine

详细信息

语法

apoc.path.combine(path1, path2)

描述

将两个给定的 PATH 值合并为一个 PATH

参数

名称

类型

描述

path1

PATH

要与第二个路径合并的第一个路径。

path2

PATH

要与第一个路径合并的第二个路径。

返回值

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);

如果我们要从包含两个 OPTIONAL MATCH 子句的查询中创建路径,可以使用 apoc.path.combine 函数。

以下返回一个路径,该路径合并了 (club)-[:IN_LEAGUE]→(league)(league)-[:IN_COUNTRY]→(country) 路径

MATCH (club:Club)
OPTIONAL MATCH path1 = (club)-[:IN_LEAGUE]->(league)
OPTIONAL MATCH path2 = (league)-[:IN_COUNTRY]->(country)
RETURN club.name, apoc.path.combine(path1, path2) AS path
ORDER BY length(path);
结果
club.name path

"尤文图斯"

(:Club {name: "尤文图斯"})-[:IN_LEAGUE]→(:League {name: "意甲"})

"曼联"

(:Club {name: "曼联"})-[:IN_LEAGUE]→(:League {name: "英超联赛"})-[:IN_COUNTRY]→(:Country {name: "英格兰"})

"弗拉门戈"

(:Club {name: "弗拉门戈"})-[:IN_LEAGUE]→(:League {name: "巴西甲级联赛"})-[:IN_COUNTRY]→(:Country {name: "巴西"})

如果我们要组合两个以上的 OPTIONAL MATCH 路径,请参见 apoc.path.create

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