简体   繁体   English

ArrangoDB - 从给定值获取所有可能的路径

[英]ArrangoDB - Get All Possible Path From Given Value

I want a query to get all possible paths that start from a given vertex.我想要一个查询来获取从给定顶点开始的所有可能路径。

For exa.例如。 as in below image,如下图所示, 在此处输入图像描述

I want to find all paths that start from "Covid/12109" with Query.我想使用 Query 查找从“Covid/12109”开始的所有路径。

So it returns like this所以它像这样返回

    { "_from":"Covid/12109","_to":"Covid/12110" }
    { "_from":"Covid/12110","_to":"Covid/12111" }
    { "_from":"Covid/12110","_to":"Covid/12115" }
    { "_from":"Covid/12110","_to":"Covid/12114" }
    { "_from":"Covid/12111","_to":"Covid/12115" }
    { "_from":"Covid/12111","_to":"Covid/12114" }
    { "_from":"Covid/12112","_to":"Covid/12110" }
    { "_from":"Covid/12112","_to":"Covid/12113" }
    { "_from":"Covid/12112","_to":"Covid/12114" }

And if i want to start from "Covid/12110" then it should return like this如果我想从“Covid/12110”开始,那么它应该像这样返回

    { "_from":"Covid/12110","_to":"Covid/12111" }
    { "_from":"Covid/12110","_to":"Covid/12115" }
    { "_from":"Covid/12110","_to":"Covid/12114" }
    { "_from":"Covid/12111","_to":"Covid/12115" }
    { "_from":"Covid/12111","_to":"Covid/12114" }
    { "_from":"Covid/12112","_to":"Covid/12110" }
    { "_from":"Covid/12112","_to":"Covid/12113" }
    { "_from":"Covid/12112","_to":"Covid/12114" }

And if i want to start from "Covid/12112" then it should return like this如果我想从“Covid/12112”开始,那么它应该像这样返回

    { "_from":"Covid/12112","_to":"Covid/12110" }
    { "_from":"Covid/12112","_to":"Covid/12113" }
    { "_from":"Covid/12112","_to":"Covid/12114" }
    { "_from":"Covid/12110","_to":"Covid/12111" }
    { "_from":"Covid/12110","_to":"Covid/12115" }
    { "_from":"Covid/12110","_to":"Covid/12114" }
    { "_from":"Covid/12111","_to":"Covid/12115" }
    { "_from":"Covid/12111","_to":"Covid/12114" }

Graph traversal is your friend here. 图遍历是你的朋友。 There are several ways to accomplish this, but you might start by:有几种方法可以做到这一点,但您可以从以下开始:

FOR c IN Covid
    FILTER c._key == '12109'
    FOR v,e IN 1..9 OUTBOUND c
        `has`
        OPTIONS { uniqueVertices: true }
        RETURN e

The name of your edge collection ('has') is tricky because HAS is an AQL keyword (see the docs about naming things with keywords).边缘集合的名称('has')很棘手,因为HAS是一个 AQL 关键字(请参阅有关使用关键字命名事物的文档)。 I've enclosed this in backticks (the AQL escape char), but you could also create a named graph , which (I believe) is much more flexible.我已将它包含在反引号(AQL 转义字符)中,但您也可以创建一个 命名的 graph ,它(我相信)更加灵活。

Looking at the query:查看查询:

  • We first find documents in the "Covid" collection that match a key.我们首先在“Covid”集合中找到与键匹配的文档。 This is optional, you could also swap the "c" in the graph traversal with a document id like "Covid/12109"这是可选的,您还可以将图形遍历中的“c”与“Covid/12109”之类的文档 ID 交换
  • FOR v,e represents "vertices" v and "edges" e to return FOR v,e表示要返回的“顶点” v和“边” e
  • 1..9 is the number of traversal "jumps" to perform. 1..9是要执行的遍历“跳转”次数。 This can be any number ( 2 ) or range ( 5..27 )这可以是任何数字 ( 2 ) 或范围 ( 5..27 )
  • OUTBOUND refers to the path direction to traverse. OUTBOUND是指要遍历的路径方向。 Other options here are OUTBOUND and ANY这里的其他选项是OUTBOUNDANY
  • { uniqueVertices: true } tells the engine to keep track of which vertices it's returned and not duplicate them on output. { uniqueVertices: true }告诉引擎跟踪它返回的顶点,而不是在 output 上重复它们。 See the docs here此处查看文档
  • RETURN e will return edge ("has") documents. RETURN e将返回边缘(“有”)文档。 RETURN v would return vertex ("Covid") documents. RETURN v将返回顶点(“Covid”)文档。

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

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