What the query does is:
- Follow all outgoing edges in edge collection
edge_collec from start vertex A
- Then sort in ascending order by edge attribute
order
- Return the vertices (the last vertex of each found path)
The edge attribute e.order is either 0 or 1:
A --[ order: 1 ]--> B
A --[ order: 0 ]--> C
B --[ order: 1 ]--> D
B --[ order: 0 ]--> E
Sorting by order will return C and E (0) before B and D (1).
Because two edges have the same value, it's undefined whether C or E is returned first, and whether B or D is returned third.
If you want the vertices at depth = 1 to be returned before the vertices at depth = 2, but still sort by order on each depth level, you can use:
SORT LENGTH(p.edges), e.order
LENGTH(p.edges) gives you the current depth of the traversal. It first sorts by depth, then by the edge attribute and will give you the desired result order: C B E D
FOR v, e, pquery above will be three arrays, and you probably want to look at saving thepresult to a variable and then execute additional queries over that. But you'll need to be familiar with the contents ofpas it contains paths, which are collections of vertices and edges. - David Thomasorderafter the traversal. C and E both have order: 0, B and D order: 1, thus C and E are sorted before B and D. Note that the possible return results are CEBD, ECBD, CEDB and ECBD. You should trySORT LENGTH(p.edges), e.orderto first sort by path length and by order attribute secondly (for equally long paths). That should give you CBED. - CodeManXSORT LENGTH(p.edges), e.ordermakes the job. Probably the simplest solution. Feel free to write a proper answer to get the credit - Tdy