简体   繁体   English

ArangoDB:图遍历中的顺序

[英]ArangoDB: order in graph traversal

I have a pretty standard graphql which represent a tree structure: 我有一个漂亮的标准graphql,它表示一个树结构:

图形

I would like to make a graph traversal and force the order according to the order I set on each edge: 我想进行遍历,并根据我在每个边上设置的order强制执行该顺序:

A -> C A-> C

A -> B -> E A-> B-> E

A -> B -> D A-> B-> D

I tried to add a SORT on my query, but it sorts the whole resulting array which is not what I want: 我试图在查询中添加SORT,但是它对整个结果数组进行了排序,这不是我想要的:

FOR v, e, p IN 1..1000 OUTBOUND A
    edge_collec
    SORT e.order
    RETURN v

Is there a way to do this using AQL? 有没有办法使用AQL做到这一点?

What the query does is: 该查询的作用是:

  • Follow all outgoing edges in edge collection edge_collec from start vertex A 从起始顶点A跟踪边缘集合edge_collec所有传出边缘
  • Then sort in ascending order by edge attribute order 然后按边缘属性order升序order
  • Return the vertices (the last vertex of each found path) 返回顶点(每个找到的路径的最后一个顶点)

The edge attribute e.order is either 0 or 1: 边缘属性e.order为0或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). order排序将在BD (1)之前返回CE (0)。 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. 因为两个边具有相同的值,所以不确定是先返回C还是E,再返回B还是D。

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: 如果要在深度= 2的顶点之前返回深度= 1的顶点,但仍按每个深度级别的order排序,则可以使用:

SORT LENGTH(p.edges), e.order

LENGTH(p.edges) gives you the current depth of the traversal. LENGTH(p.edges)为您提供当前的遍历深度。 It first sorts by depth, then by the edge attribute and will give you the desired result order: CBED 它首先按深度排序,然后按edge属性排序,然后将为您提供所需的结果顺序: CBED

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM