Path pattern prefix
When defining path patterns, we can specify a search prefix and a path mode. The path mode will filter results if elements are repeated in a path, and the search prefix will select the paths by their length.
When using a search prefix, the results are partitioned, so that each path from a partition has the same first and last node. Then, a result is selected from each partition.
Search prefix |
Description |
---|---|
|
All paths. The default search prefix. |
|
Any path for each partition. |
|
All shortest paths. |
|
Any shortest path for each partition. |
|
The k shortest paths for each partition. |
Path mode |
Description |
---|---|
|
Does not filter any path. The default path mode. |
|
Filters paths with repeated edges. |
|
Filters paths with repeated nodes. |
|
Filters paths with repeated nodes, unless the repeated nodes are the first and last nodes. |
Examples
In this query, we return paths of followers, without any repeated nodes. If this query does not contain the ACYCLIC
keyword, then it is an invalid query.
MATCH ACYCLIC p = (a)-[:Follows]->*(b)
RETURN p
In this query, we return again a path of followers, but selecting all shortest paths for each pair of followers.
MATCH ALL SHORTEST ACYCLIC p = (a)-[:Follows]->*(b)
RETURN p
In this query, we return all trails of length 2.
MATCH TRAIL p = ()->{2}()
RETURN p