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

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

问题描述

如何获取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

位置(顶点)"集合包含23753个文档,而连接(边)"集合具有123414个文档.

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

推荐答案

如果通过选项filterVertices将目标过滤器放到遍历"中,则可以大大加快查询速度,以给出应触摸的顶点的示例通过遍历.使用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:如何获取2个顶点之间的所有可能路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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