Search code examples
joinneo4jreturncypher-3.1

Join Keys from 2 nodes in a single return value in Neo4j 3.2.15 and cypher-3.1


I'm trying to get a "Friend Recommendation" query. The nodes have the next sequence (Node) - [FRIEND] - (Node) - [INFO] - (P_info) where every node have a INFOrelation with a P_info node asociated. I can get a list of recommended friends of a Node but i need to include the P_info keys into recommended friends keys to return all together.

This is my query at the moment:

match (person:Account{_id:"185860469"})
match (person)-[:FRIEND]-()-[:FRIEND]-(potentialFriend)
where not (person)-[:FRIEND]-(potentialFriend)
match (potentialFriend)-[:INFO]-(information:P_info)
with person,potentialFriend, COUNT(*) AS friendsInCommon,information
where friendsInCommon > 5
return {user:person,recommend:collect(potentialFriend)},{info:information}

but the information of "info" is not asociated with "potentialFriend" at the response. I want to do something like this: return {user:person,collect(potentialFriend,information)} but i don't know if it's possible, cypher says:

Too many parameters for function 'collect'

thanks in advance.


Solution

  • I did it, just adding an additional WITH.I leave the answer in case someone helps

    WITH person,{friend_id:potentialFriend._id,friend_name:information.name} AS Recommended_friend
    RETURN person._id,collect(Recommended_friend)
    

    this will return an unique response with person id and an array with all the recommended friends for him.