0

Lets say I have 2 anonymous traversals A and B. The result for traversal A is V[1], V[2], V[3] and the result for traversal B is V[3], V[4] and V[5].

Both A and B are searching for properties both of which will not be in any single vertex.

"A" traversal searches for property (x == y) which is in V[1] and V[1] is connected to V[2] and V[3] which are part of the traversal result.

"B" traversal searches for property (u == w) which is in V[5] and V[5] is connected to V[3] and V[4] which are part of the traversal result.

How do I find the intersection of these results?

I tried doing :

__.and(A, B)

But the result of this is not intersection.

For E.g:

A = __.has('name', 'marko').out()

B = __.has('name', 'josh').out()

__.and(A, B) is not correct.

Note: Took the above example for simplicity. In actual query A & B is quite big with multiple unions in each of them.

I went through the following links:

https://groups.google.com/forum/#!msg/gremlin-users/6_MRJxBnivo/wT_71IAzCwAJ

gremlin intersection operation

All the suggestions here have provided a way to do intersection provided the vertex satisfies all the conditions which is not the case here.

Akhil
  • 511
  • 1
  • 8
  • 13

1 Answers1

1

So you can try to do the intersection with groupCount step:

g.V().union(
    __.has('name', 'marko').out(),
    __.has('name', 'josh').out()
).groupCount().by().unfold()
.where(select(values).is(gt(1))).select(keys)

Another way is to use the simplified query that Stephen suggested in the post you mentioned:

g.V().has('name', 'marko').out().as('a').
V().has('name', 'josh').out().as('b').
select('a').
where('a',eq('b'))

I tried both of them here: https://gremlify.com/31

noam621
  • 2,766
  • 1
  • 16
  • 26