Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArangoDB uniqueVertices global excluding the first and last vertices

Tags:

arangodb

I'm attempting to find all unique paths from one friend to another.

When I use uniqueVertices: 'global', it is only returning one path because the end vertices is considered is part of the global unique.

FOR v,e,p
IN 1..6
ANY "entities/foo" 
GRAPH "friendGraph"
OPTIONS {
bfs: true,
uniqueVertices: 'path'
}
SORT e.weight ASC
FILTER v._id == "entities/bar"
RETURN p

Is there a way to have uniqueVertices: 'global' ignore the end vertices? I know there isn't a way to specifically do that. But is there a way to accomplish the same thing?

'path' resulted in way to many results.

Thank you.

like image 983
Chemdream Avatar asked Dec 05 '25 16:12

Chemdream


1 Answers

In order to use globally unique vertices but for the last one, you could add the last step in the path manually like so:

FOR v,e,p
IN 0..5
ANY "entities/foo"
GRAPH "friendGraph"
OPTIONS {
    bfs: true,
    uniqueVertices: 'global'
}
FILTER p.vertices[*]._id ALL != "entities/bar"
FOR w,f
IN 1..1
ANY v
GRAPH "friendGraph"
FILTER w._id == "entities/bar"
SORT f.weight ASC
RETURN { edges: APPEND(p.edges, [f]), vertices: APPEND(p.vertices, [w]) }

I'd like to note two things:

  • the SORT operation you added might not achieve what you want: it sorts the paths by the weight of the path's last edge
  • this does not find all unique paths between the two vertices. For that using the option uniqueVertices: 'path' would be correct, and there might well be a lot of them.
like image 189
Tobias Gödderz Avatar answered Dec 08 '25 22:12

Tobias Gödderz