简体   繁体   中英

ArangoDB: is it possible to 'fake' edges in a graph traversal?

I've got a complex graph. I am using a traversal (through ArangoJS) with also quite complex expanderFunction and traversalVisitor.

For this traversal, I'd like to know if it is possible to create dynamic relations (or fake relations) between some nodes in my graph): That is, based on some attributes in a vertex, let the traversal pursue the graph exploration as if there was an edge between the current vertex and another one.

I've tried to trick the expander function, pushing a fake edge ( from the current vertex to another not related one in the graph) into the traversal data structures, something like:

if (complex_criteria(vertex)) {
    var unconnectedVertexId = ... 
    var unconnectedVertex = someCollection.document(unconnectedVertexId);
    connected.push({ edge:{_id:'newId', _from:vertex._id, _to:unconnectedVertex._id}, vertex: unconnectedVertex });
}
..
return connected;

This did not work. ( traversal options were: direction: 'outbound', strategy: "depthfirst" )

Any better idea ?

Thanks !

i think there is a slight mistake in you code:

if (complex_criteria(vertex)) {
    var unconnectedVertexId = ... 
    var unconnectedVertex = someCollection.document(unconnectedVertexId);
    connected.push({ edge:{_id:'newId', _from:vertex._id, _to:unconnectedVertex._id}, vertex: unconnectedVertex });
}
..
return connected;

the "fake-edge" _to has to point to unconnectedVertex._id , not the object itself. Can you check if this fixes the problem already?

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