2
votes

I have document collections dc1 and dc2 and edge collections ec1 and ec2. I use dc1 and ec1 for graph g1 creation and dc2 and ec2 for graph g2.

I perform some search request and get result set which contains documents d1 from collection dc1 and d2 from collection dc2.

And I want to represent search result set in graph viewer as 2 graphs to be able to graphically exlpore possible relations between d1 and other documents in collection dc1 and so for d2 and documents from dc2.

Can I do it in current version of ArangoDB? Do you know any existing additional apps (services, foxx apps) for it?

Now, as dirty trick I created 3rd document collection DC containing documents from both collections dc1 and dc2 and corresponded edge collection EC containing edges from both collections ec1 and ec2, add new node search result into DC and relations into EC represented found dc1 and dc2 and then how graph build based on DC and EC starting with vertex search result. It let me exlore any relations between found results and document from corresponded initial collections.

I think about creation my own foxx app for it (perhaps with temporal collection or something else) if such does not exists yet.

1
The current version of the graph viewer can only display one graph set at once.dothebart
@dothebart, do you have any plans to implement multi graph viewer soon? If so, when? Otherwise we will try to implement it by ourselves. Also, my primary qestion is about search result showing as graph. Currently, I try to create stub with multi collection graph.zubactik
No, we're currently not intending to add a second graph. Usually browsers tend to be rather busy with the first one already ;-) But - the source is out there, so you may help yourselves. Do I get that correctly that your usecase resembles the city routing example graph as used in the Graph Functions documentation?dothebart
I'm sorry I mixed 2 questions in one. My primary question is "how to show search results in graph viewer if result set contains documents from several collections and such documents have some relations in their corresponded edge collections". At the moment I use multi collection graph to represent it and my own javascript function for it, but it is only hack. I did not find in documentation such functionality and I'm interested do you have dev plans to implement such feature and if so when? In other case we will try to implement it by our own.zubactik
You would probably intersect two AQL queries using an inner join - like in FILTER f.friendOf == u.userId && f.type == "friend"dothebart

1 Answers

3
votes

Currently its not possible to directly show the result of a graph traversal in the graph viewer.

You can however copy the results of a traversal into a temporary graph which you then can display. We will do this using the City graph

As an example we start from Berlin, and want to only view cities that aren't capitals. The original AQL Traversal with this filter would be:

FOR v, e IN 1..1 OUTBOUND 'germanCity/Berlin' GRAPH 'routeplanner'
  FILTER v.isCapital == false
  RETURN {City: v, Highway: e}

We now create the temporary graph:

db._createEdgeCollection('temporaryEdgeCollection', {volatile: true})
db._create('temporaryVertexCollection', {volatile: true})
db._graphs.save({
   "_key": "tempgraph",
  "orphanCollections" : [ ], 
  "edgeDefinitions" : [ 
  {
    "collection": "temporaryEdgeCollection",
    "from": ["temporaryVertexCollection"],
    "to": ["temporaryVertexCollection"]
    }
    ]
})

Now we edit the above query to actually copy the graph into the temporary collections we created above. The challenge is that we actually need the startnode there too, since we want to display it.

We may not do several INSERT statements to the same collections, so we need so regroup the vertices into a list that also contains the startvertex:

db._query(`
LET startVertex = DOCUMENT('germanCity/Berlin')
LET traversalResult = (
  FOR v, e IN 1..1 OUTBOUND startVertex GRAPH 'routeplanner'
    FILTER v.isCapital == false
    LET newEdge = MERGE(e, {
      _from: CONCAT(@tv, '/', SPLIT(e._from, '/')[1]),
      _to: CONCAT(@tv, '/', SPLIT(e._to, '/')[1])
     })
    LET newV = UNSET(v, '_id')
    RETURN {v: newV, e: newEdge}
  )
LET x=(
  FOR vertex in PUSH(traversalResult[*].v, UNSET(startVertex, '_id'))
    INSERT vertex INTO temporaryVertexCollection)
LET y=(
  FOR edge in traversalResult[*].e
    INSERT edge INTO temporaryEdgeCollection)
RETURN 1
`,
{tv : 'temporaryVertexCollection'})

Now you can actualy click to the tempgraph in the webinterface, an visualise the actual result.

Note that we used volatile collections, so we don't waste disk space for this.