Statement ab().src().dest().depth()
can find and return paths from an initial-node to a terminal-node, by specifying depth (number of edges), applying filters on the nodes and edges, as well as removing (or not) paths that have circles.
Syntax:
- Statement alias supported (PATH type)
- All parameters:
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 |
dest() |
Filter | Mandatory | The filtering rules of the end node; error will occur if multiple nodes are found | NODE |
depth() |
Range | Mandatory | To set the depth of the path depth(N) : N edges depth(:N) : 1~N edges depth(M:N) : M~N edges depth(N).shortest(<>) : the shortest (or the least weighted) paths within N edges |
Not supported |
shortest() |
/ or @<schema>.<property> |
Numeric edge property; LTE is required | When no edge property is specified, return the shortest path; when edge property is specified, return the least weighted paths using the specified property as the weight factor (edges without the property do not form the path). When shortest() is used, value inside depth() should be a constant, that is, depth(N).shortest(<>) , means the shortest (or the least weighted) paths within N edges |
Not supported |
node_filter() |
Filter | The filtering rules that nodes other than src and dest need to satisfy |
Not supported | |
edge_filter |
Filter | The filtering rules that all edges need to satisfy | Not supported | |
path_ascend() |
@<schema>.<property> |
Numeric edge property; LTE is required | To return paths where the specified property ascends (edges without the property do not form the path) | Not supported |
path_descend() |
@<schema>.<property> |
Numeric edge property; LTE is required | To return paths where the specified property descends (edges without the property do not form the path) | Not supported |
direction() |
String | left, right | To specify the direction of the edge | Not supported |
no_circle() |
/ | / | To dismiss the paths that have circles; see Basic Concept - Terminologies for the definition of circle | Not supported |
limit() |
Int | -1 or >=0 | Number of results to return in single execution, -1 means to return all results | Not supported |
N steps
Example: Find ten 4-step paths from Card CA001 to Card CA002, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(4) as p
limit 10
return p{*}
1~N steps
Example: Find 10 paths from Card CA001 to Card CA002 within 4 steps, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4) as p
limit 10
return p{*}
M~N steps
Example: Find 10 paths from Card CA001 to Card CA002 within 2~4 steps, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(2:4) as p
limit 10
return p{*}
Non-weighted Shortest Path
Example: Find 10 shortest 4-step paths from Card CA001 to Card CA002, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(4)
.shortest() as p
limit 10
return p{*}
Weighted Shortest Path
Example: Find 10 shortest 4-step paths weighted by @transfer.amount from Card CA001 to Card CA002, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(4)
.shortest(@transfer.amount) as p
limit 10
return p{*}
node_filter()
Example: Find 10 paths from Card CA001 to Card CA002 within 4 steps return all non-@card node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.node_filter({!@card}) as p
limit 10
return p{*}
edge_filter()
Example: Find 10 paths from Card CA001 to Card CA002 within 4 steps, return all node and non-@transaction edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.edge_filter({!@transfer}) as p
limit 10
return p{*}
path_ascend()
Example: Find 10 paths from Card CA001 to Card CA002 within 4 steps, return all node and @transfer edge properties in an ascending order of time
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.path_ascend(@transfer.time) as p
limit 10
return p{*}
path_descend()
Example: Find 10 paths from Card CA001 to Card CA002 within 4 steps, return all node and @transfer edge properties in a descending order of time
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.path_descend(@transfer.time) as p
limit 10
return p{*}
direction(right)
Example: Find 10 paths with a right direction from Card CA001 to Card CA002 within 4 steps, return all node and @transfer edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.edge_filter({@transfer}).direction(right) as p
limit 10
return p{*}
direction(left)
Example: Find 10 paths with a left direction from Card CA001 to Card CA002 within 4 steps, return all node and @transfer edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(:4)
.edge_filter({@transfer}).direction(left) as p
limit 10
return p{*}
no_circle()
Example: Find ten 5-step paths that must not contain circled paths and are from Card CA001 to Card CA002, return all node and edge properties
ab().src({_id == "CA001"}).dest({_id == "CA002"}).depth(5)
.no_circle() as p
limit 10
return p{*}
limit()
Example: Find 5-step paths from Card CA001 to Card CA002 to Node 10 respectively, return 3 paths from each set with all node and edge properties
uncollect ["CA001","CA002"] as n
ab().src({_id == n}).dest({_id == "CA005"}).depth(5)
.limit(3) as p
return p{*}