在 AQL 中按类型过滤图边的最佳方法是什么 [英] Whats the best method to to filter graph edges by type in AQL

查看:26
本文介绍了在 AQL 中按类型过滤图边的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下超级简单的图形:

I have the following super-simple graph :

我想做的是:

  1. 选择问题文档中存在名为 firstQuestion 且值为 true 的属性的所有问题.
  2. 选择通过 with_options 类型的出站边连接到问题的任何选项

以下查询有效,但是感觉必须有更好的方法来检查边类型而不使用字符串操作 - 特别是我用来通过将边 _id 值连接到具有边类型的键来重新创建边 _id 值的连接操作我想要 - 这是检查边缘类型的最佳方法吗?

The following query works, however it feels like there must be a better way to inspect the edge type without using string operations - specifically the concatenation operation i use to recreate the edge _id value by joining it to the key with the edge type i want - is this the best way to inspect the type of edge?

FOR question IN questions 
FILTER question.firstQuestion == true
    let options = 
        (FOR v, e IN 1..1 OUTBOUND question._id GRAPH 'mygraph'
        FILTER CONCAT('with_options/', e._key) == e._id
        RETURN v)
RETURN {question: question, options: options}

推荐答案

我们目前正在推出 IS_SAME_COLLECTION 用于 ArangoDB 2.8.1 的特定目的.在这种情况下,DOCUMENT 函数也值得一提.

We're currently introducing IS_SAME_COLLECTION for that specific purpose with ArangoDB 2.8.1. The DOCUMENT function is also worth to mention in this context.

FOR question IN questions 
  FILTER question.firstQuestion == true
  LET options = (FOR v, e IN 1..1 OUTBOUND question._id GRAPH 'mygraph'
                   FILTER IS_SAME_COLLECTION('with_options', e._id)
                     RETURN v)
  RETURN {question: question, options: options}

然而,在这种特殊情况下最好的解决方案不是使用命名图形接口,而是首先指定遍历应该关注的边集合列表:

However, the best solution in this special case is not to use the named graph interface, but specify the list of edge collections that should be concerned by the traversal in first place:

FOR question IN questions 
  FILTER question.firstQuestion == true
  LET options = (FOR v, e IN 1..1 OUTBOUND question._id with_options RETURN v)
  RETURN {question: question, options: options}

这篇关于在 AQL 中按类型过滤图边的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆