ArangoDB:如何获得两个顶点之间的所有可能路径? [英] ArangoDB : How to get all the possible paths between 2 vertices?

查看:34
本文介绍了ArangoDB:如何获得两个顶点之间的所有可能路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 maxDepth = 2 的情况下获得 2 个顶点(例如 X 和 Y)之间的所有可能路径?

我尝试使用 TRAVERSAL,但执行时间大约需要 10 秒.这是查询:

I tried with TRAVERSAL but it is taking around 10 seconds to execute. Here is the query :

FOR p IN TRAVERSAL(locations, connections, "X", "outbound", { minDepth: 1, maxDepth: 2, paths: true }) 
FILTER p.destination._key == "Y" 
RETURN p.path.vertices[*].name

locations(vertices)集合有23753个文档,connections(edges)集合有123414个文档.

The locations (vertices) collection has 23753 documents, and the connections (edges) collection has 123414 documents.

推荐答案

如果通过选项 filterVertices 将目标过滤器直接放入 Traversal 中,可以大大加快查询速度遍历应该触及的顶点.使用 vertexFilterMethod 您可以定义所有与示例不匹配的顶点应该发生什么.

You can speed up the query a lot if you put the filter for destination right into Traversal via the options filterVertices to give examples of vertices that should be touched by the traversal. With vertexFilterMethod you can define what should happen with all vertices that do not match the example.

因此,在您的查询中,您只想匹配目标顶点Y",并且所有其他顶点都应通过但不包含在结果中,exclude.

So in your query you only want to match the target vertex "Y" and all other vertices should be passed through but not included in the result, exclude.

这使得后来的 FILTER 过时了.目前,内部优化器无法自动执行此操作,但这种魔法已在我们的路线图上.

This makes the later FILTER obsolete. Right now the internal optimizer is not able to do that automagically but this magic is on our roadmap.

这是一个包含优化的查询:

This is a query containing the optimization:

FOR p IN TRAVERSAL(locations, connections, "X", "outbound", { minDepth: 1, maxDepth: 2, paths: true, filterVertices: [{_key: "Y"}], vertexFilterMethod: ["exclude"]})
RETURN p.path.vertices[*].name

这篇关于ArangoDB:如何获得两个顶点之间的所有可能路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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