How to intersect results of two pipes?

535 views
Skip to first unread message

Jack

unread,
Jan 24, 2012, 7:22:50 AM1/24/12
to Gremlin-users
I have a graph with user nodes and item nodes. Users are connected to
items they own and to users they know.
I want to define a traverse that for a target user TU will find all
items that he has in common with the users he is connected to.
For example:
1. User TU is connected to user B and user C
2. User TU owns items: 1, 2, and 3.
3. User B owns item 1
4. User C owns item 3

The traverse result will be [1, 3].

So far I have this: TU.out('knows').out('owns') which returns me all
C's and B's items, but how do I intersect them with A's own 'owns'
nodes?

Thanks

Marko Rodriguez

unread,
Jan 26, 2012, 10:25:04 AM1/26/12
to gremli...@googlegroups.com
Hi Jack,

I just answered a similar question on the Neo4j mailing list and put my answer on StackOverflow. See:


Repeated here in your terms:

TU.out('knows').out('owns').in('owns').filter{it == TU}.back(2)

Here is what the expression says:

1. Start at vertex TU.
2. Find TU's friends.
3. Find what TU's friends own.
4. Find who else owns those same items.
5. Filter out those people who are not TU.
6. Go back 2 steps to the items that are co-owned with TU.

HTH,
Marko.

Jack

unread,
Jan 27, 2012, 3:14:45 PM1/27/12
to Gremlin-users
Thank you very much! Works great.
> > Thanks- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages