Get introduced (linkedin like)

40 views
Skip to first unread message

Amit Gupta

unread,
Jan 3, 2013, 9:23:57 AM1/3/13
to ne...@googlegroups.com
Hi, 
I am using neo4j with people and companies as nodes and friend_of/works_at relationship between these.
I would like to know how to implement a get introduced to a second degree connection that linked in uses. The idea is to get your second degree connections at the company you wish to apply. If there are these second degree connections, then you would like to know who among your 1st deg connections can introduce y*ou to these 2nd deg connections.

For this I'm trying this query : 

    START from = node:Nodes(startNode), company = node:Nodes(endNode)
    MATCH from-[:FRIEND_OF]->f-[:FRIEND_OF]-fof-[:WORKS_AT]->company
    WHERE not(fof = from) and not (from-[:FRIEND_OF]->fof)
    RETURN distinct f.name, fof.name, company.name

But, this returns duplicate friend of friend names (fof.name), since the distinct is applied on all the parameters that are returned as a whole. It could be like I have friends X and Y who are both connected to Z who works at company C. This way, I get both X-Z-C and Y-Z-C. But, I want to apply distinct on Z, such that I get either X-Z-C or Y-Z-C or maybe a list/collection/aggregate of all friends that connect to Z. This could like ["X","Y"..]->Z How should I modify my query?

Cheers,
Amit Gupta

Wes Freeman

unread,
Jan 3, 2013, 10:21:36 AM1/3/13
to ne...@googlegroups.com
Hey Amit,

I would do a collect, like:

RETURN f.name, collect(distinct fof.name) as friends_of_friends, company.name

Wes


--
 
 

Amit Gupta

unread,
Jan 3, 2013, 10:40:15 AM1/3/13
to ne...@googlegroups.com
Hi wes, but this doesn't solve the problem..
what I want to know is some of my friends who can connect me with a 2nd deg friend.
So, in the case my friends x and y can connect me to z, i should have ["x", "y"] -> z.

The query above gives me some 1st deg friends (duplicated) and a list of 2nd deg friends they can introduce. Also, as I stated this list is duplicated. I want the results the other way round..

Wes Freeman

unread,
Jan 3, 2013, 10:56:21 AM1/3/13
to ne...@googlegroups.com
It would help if you built a sample graph in console.neo4j.org, so we can poke at it.

Maybe you want the collect on the f.name instead of the fof.name?

--
 
 

Reply all
Reply to author
Forward
0 new messages