0
votes

Take US cities for example and say I want the traversal of all cities and roads that go through NYC, Chicago and Seattle.

This can be done with TRAVERSAL AQL function (using filterVertices). However this function only takes the ID and not the vertex example as in GRAPH_TRAVERSAL.

The GRAPH_TRAVERSAL doesn't have a filter option, so my question is there a way to filter the results using graph operations?

1

1 Answers

1
votes

the feature is actually there but was somehow not documented. I added it to our documentation which should be updated soon. Sorry for the inconvenience.

filterVertices takes a list of vertex examples.

  • Note: you can also give the name of a custom AQL function. with signature function(config, vertex, path). For more specific filtering.

vertexFilterMethod defines what should be done with all other vertices:

  • "prune" will not follow edges attached to these vertices. (Used here)
  • "exclude" will not include this specific vertex.
  • ["prune", "exclude"] both of the above. (default)

An example query for your question is the following (airway is my graph):

FOR x in GRAPH_TRAVERSAL("airway", "a/SFO", "outbound", {filterVertices: [{_key: "SFO"}, {_key: "NYC"}, {name: "Chicago"}, {name: "Seattle"}], vertexFilterMethod: "prune"}) RETURN x

Hint: Make sure you include the start vertex in the filter as well. Otherwise it will always return with an empty array (the first visited vertex is directly pruned)