Domanda

I am trying to make a complex query on the graph and was successfully able to do it. The vertices that were output in that query also had some alias vertices connected to these vertices by an alias relationship.

Now I am looking to output all the previous vertices with their alias vertices but I can do either/or (either original vertices or the alias vertices for each vertex).

If anyone knows a way to output the adjacent vertices of a particular vertex and also output that vertex in the same query I think my problem would be solved.

Any suggestions?

È stato utile?

Soluzione

Let's consider the following example:

[AliasUser1] <---'alias'--- [User1] ---'likes'---> [ItemA] <---'likes'--- [User2] ---'alias'---> [AliasUser2]

With the following code:

result = [] as Set;
user1.out('likes')  // we are at ItemA
     .in('likes')   // we are at User2 but also back at User1
     .store(result) // store the users vertices
     .out('alias')  // we are at the alias vertices 
     .store(result) // store the alias vertices
     .iterate()     // run

You get:

gremlin> result.name
==>User2
==>AliasOfUser2
==>User1
==>AliasOfUser1

So I guess store is key to the solution of your problem.

Hereafter the sample graph of the example:

g = new TinkerGraph()

user1 = g.addVertex()
user1.name ='User1'
user2 = g.addVertex()
user2.name ='User2'
itemA = g.addVertex()
itemA.name ='ItemA'
myAlias1 = g.addVertex()
myAlias1.name ='AliasOfUser1'
myAlias2 = g.addVertex()
myAlias2.name ='AliasOfUser2'

g.addEdge(user1, itemA, 'likes')
g.addEdge(user2, itemA, 'likes')
g.addEdge(user1, myAlias1, 'alias')
g.addEdge(user2, myAlias2, 'alias')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top