Automatic Spread is a query method that explores the neighborhood of the start node through iteratively searching for 1-Hop neighbors layer by layer. Spreading is executed on each node in one layer, after all nodes in one layer is done, move to the nodes in the next layer. Specifying the direction of the edge would affect the order of paths that returned. limit
clause defines the maximum number of 1-Hop paths to return.
Automatic Spread is a BFS (Breadth First Search) query method that is commonly used in graph query/analysis industry for observing layers of relationship around an entity, and to retrieve and acquire data quickly.
Syntax:
- Command:
spread()
- Parameter: (see the table below)
- Statement Alias: Custom alias supported, structure type is PATH
Parameter | Type | Specification | Description | Structure Type of Custom Alias |
---|---|---|---|---|
src() |
Filter | Mandatory | The filtering rules of the start node; error will occur if multiple nodes are found | NODE |
depth() |
Int | >0; mandatory | The maximum depth to spread | Not supported |
node_filter() |
Filter | The filtering rules that neighbor nodes other than src need to satisfy |
Not supported | |
edge_filter() |
Filter | The filtering rules that all edges need to satisfy | Not supported | |
direction() |
String | left, right | To specify the direction of the edge | Not supported |
limit() |
Int | -1 or >=0 | Number of results to return, -1 means to return all results | Not supported |
1~N Steps
Example: Spread from Card CA001 for 3 steps, return 10 one-step paths with their properties
spread().src({_id == "CA001"}).depth(3) as p
limit 10
return p{*}
node_filter()
Example: Spread from Card CA001 for 3 steps, filter all @card nodes, return 10 one-step paths with their properties
spread().src({_id == "CA001"}).depth(3)
.node_filter({!@card}) as p
limit 10
return p{*}
edge_filter()
Example: Spread from Card CA001 for 3 steps, filter all @transfer edges, return 10 one-step paths with their properties
spread().src({_id == "CA001"}).depth(3)
.edge_filter({!@transfer}) as p
limit 10
return p{*}
direction(right)
Example: Spread from Card CA001 for 3 steps, filter all edges in the right direction, return 10 one-step paths with their properties
spread().src({_id == "CA001"}).depth(3)
.direction(right) as p
limit 10
return p{*}
direction(left)
Example: Spread from Card CA001 for 3 steps, filter all edges in the left direction, return 10 one-step paths with their properties
spread().src({_id == "CA001"}).depth(3)
.direction(left) as p
limit 10
return p{*}
limit()
Example: Spread from Card CA001 and Card CA002 for 3 steps, return 20 one-step paths with their properties for each node
uncollect ["CA001","CA002"] as n
spread().src({_id == n}).depth(3)
.limit(20) as p
return p{*}