1. 定义
搜素子图的过程使用与路径扩展类似的方法从指定节点出发、沿着特定关系类型遍历,并返回能够到达的所有节点和关系。
APOC提供两种搜素子图的过程:
- subgraphNodes():仅返回可以到达的节点;
- subgraphAll():返回节点和关系。
与路径扩展过程expand和expandConfig不同的是,上述两个过程不返回所有的路径。
2. 应用
搜索子图的过程不会遍历所有可能的路径(即节点和边的所有可能序列),因此在执行效率和成本方面都优于路径扩展过程。适用的场景包括:
- 寻找节点的k-度邻居(k-nearest neighbours);
- 判断节点之间是否连通;
- 对图进行划分子图的操作。
合理使用 CALL apoc.path.subgraphNodes
MATCH (intopice:Intopiece) WHERE intopice.order_number = "待输入"
CALL apoc.path.subgraphNodes(intopice, {maxLevel:1}) YIELD node
return node.order_number as order_number ,node.into_state as into_state,node.roster_type as roster_type
----
MATCH (intopice:Intopiece) WHERE intopice.order_number = "待输入"
CALL apoc.path.subgraphNodes(intopice, {maxLevel:2}) YIELD node
return node.order_number as order_number ,node.into_state as into_state,node.roster_type as roster_type