简体   繁体   English

ArangoDB:如何获取2个顶点之间的所有可能路径?

[英]ArangoDB : How to get all the possible paths between 2 vertices?

How to get all the possible paths between 2 vertices (eg. X and Y) with maxDepth = 2? 如何获得maxDepth = 2的2个顶点之间的所有可能路径(例如X和Y)?

I tried with TRAVERSAL but it is taking around 10 seconds to execute. 我尝试使用TRAVERSAL但是执行大约需要10秒钟。 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

The locations (vertices) collection has 23753 documents, and the connections (edges) collection has 123414 documents. 位置(顶点)集合包含23753个文档,而连接(边)集合具有123414文档。

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. 如果通过选项filterVertices将目标过滤器直接放入Traversal中,则可以filterVertices加快查询速度,以提供遍历应触及的顶点示例。 With vertexFilterMethod you can define what should happen with all vertices that do not match the example. 使用vertexFilterMethod可以定义与示例不匹配的所有顶点应该发生的情况。

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 . 因此,在您的查询中,您只想匹配目标顶点“ Y”,并且所有其他顶点都应通过,但不包括在结果中( exclude

This makes the later FILTER obsolete. 这使得后面的FILTER变得过时了。 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

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

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