Skip to content

Commit

Permalink
add-find-single-shortest-path (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
abby-cyber authored Aug 17, 2023
1 parent 71eb73e commit 31d7911
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions docs-2.0/3.ngql-guide/16.subgraph-and-path/2.find-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `FIND PATH` statement finds the paths between the selected source vertices a
## Syntax

```ngql
FIND { SHORTEST | ALL | NOLOOP } PATH [WITH PROP] FROM <vertex_id_list> TO <vertex_id_list>
FIND { SHORTEST | SINGLE SHORTEST | ALL | NOLOOP } PATH [WITH PROP] FROM <vertex_id_list> TO <vertex_id_list>
OVER <edge_type_list> [REVERSELY | BIDIRECT]
[<WHERE clause>] [UPTO <N> {STEP|STEPS}]
YIELD path as <alias>
Expand All @@ -19,7 +19,9 @@ YIELD path as <alias>
[vertex_id [, vertex_id] ...]
```

- `SHORTEST` finds the shortest path.
- `SHORTEST` finds all the shortest path.

- `SINGLE SHORTEST` finds the all shortest path. If there are multiple shortest paths, only one path is returned.

- `ALL` finds all the paths.

Expand All @@ -35,9 +37,11 @@ YIELD path as <alias>

- `<WHERE clause>` filters properties of edges.

- `<N>` is the maximum hop number of the path. The default value is `5`.
- `UPTO <N> {STEP|STEPS}` is the maximum hop number of the path. The default value is `5`.

- `ORDER BY $-.path` specifies the order of the returned paths. For information about the order rules, see [Path](https://github.com/vesoft-inc/nebula/blob/{{nebula.branch}}/src/common/datatypes/Path.h#L86).

- `<M>` specifies the maximum number of rows to return.
- `LIMIT <M>` specifies the maximum number of rows to return.

!!! note

Expand Down Expand Up @@ -75,6 +79,35 @@ nebula> FIND SHORTEST PATH WITH PROP FROM "team204" TO "player100" OVER * REVERS
+--------------------------------------------------------------------------------------------------------------------------------------+
```

```ngql
nebula> FIND SHORTEST PATH FROM "player100", "player130" TO "player132", "player133" OVER * BIDIRECT UPTO 18 STEPS YIELD path as p;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| p |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <("player100")<-[:follow@0 {}]-("player144")<-[:follow@0 {}]-("player133")> |
| <("player100")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player109")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player104")-[:serve@20182019 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| ... |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player109")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| ... |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

```ngql
nebula> FIND SINGLE SHORTEST PATH FROM "player100", "player130" TO "player132", "player133" OVER * BIDIRECT UPTO 18 STEPS YIELD path as p;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| p |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <("player100")<-[:follow@0 {}]-("player144")<-[:follow@0 {}]-("player133")> |
| <("player100")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

```ngql
nebula> FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0 YIELD path AS p;
+------------------------------------------------------------------------------+
Expand Down

0 comments on commit 31d7911

Please sign in to comment.