已遍历的过滤器路径

时间:2019-07-15 05:58:22

标签: gremlin tinkerpop

Given a query 
    gremlin> g.V(1).repeat(out()).times(2).emit().path()
    ==>[v[1],v[3]]
    ==>[v[1],v[2]]
    ==>[v[1],v[4]]
    ==>[v[1],v[4],v[5]]
    ==>[v[1],v[4],v[3]]

这里我们使用了send,它将在每个循环中发出所有结果。在响应中,我们有[v [1],v [4]]和[v [1],v [4],v [5]]。我不希望[v [1],v [4]]出现在我的响应中,因为我已经知道[[[1],v [4],v [5]]之间存在一条路径]和v [4]。有没有一种方法可以过滤路径,使我没有遍历的路径?

1 个答案:

答案 0 :(得分:1)

显然,较长的路径是找到的最后一条路径。获取所有非循环最长路径的查询是:

gremlin> g.V(1).repeat(out().simplePath()).
                  until(__.not(out().simplePath())).
                path()
==>[v[1],v[3]]
==>[v[1],v[2]]
==>[v[1],v[4],v[5]]
==>[v[1],v[4],v[3]]

对于2的固定深度为:

gremlin> g.V(1).repeat(out().simplePath()).
                  emit(__.not(out().simplePath())).
                  times(2).
                path()
==>[v[1],v[3]]
==>[v[1],v[2]]
==>[v[1],v[4],v[5]]
==>[v[1],v[4],v[3]]