简体   繁体   中英

ArangoDB Graph-Traversal: Exclude Edges

I'm executing a query similar to:

FOR v, e IN 1..10 ANY @start GRAPH @graph
    FILTER e.someCondition
    RETURN v

What I expected to happen was that if e.someCondition was false , then the edge in question wouldn't be traversed (and transitively, all other vertexes and edges reachable solely through e would never be visited).

However, it seems that what happens is that e is merely skipped and then traversal continues down that path.

So, how can I set boundaries on graph-traversal by edge-properties using AQL?

The query supports v, e and p, where p is the path it takes.

The ArangoDB documentation shows some examples.

I have used this to exclude specific nodes at specified depths in the path but you have to specify depth of nodes eg p.vertices[0].something != 'value' ).

Another thing you might want to look at is working with 'Custom Visitor' functions which are evaluated as the query traverses down a path.

This good blog post and this ArangoDB guide show some real world examples of it and it's well worth the read and effort to get a sample working. I've used these functions to summarise data in a path, aggregated by properties on the vertices in the path, but you can also use it to have custom paths followed.

This is worth the effort because it gives you huge flexibility over the computation it follows when traversing the graph. You can exclude branches, only include branches that meet specific requirements, or aggregate data about the paths it took.

I hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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