I have been into a finer point of Cypher syntax and I keep running into dead ends when searching about this issue.
The goal is relatively simple: I have a social graph made of Persons following Groups.
I would like to simplify it by creating a relationship between groups that have members in common... but I would like to weigh these relationships by the number of members they have in common.
I came up with this query:
MATCH p=(g1:Group)< -[r1:IS_MEMBER_OF]-(u:Person)-[r2:IS_MEMBER_OF]- >(g2:Group) MERGE (g1)-[r:SHARES_MEMBERS_WITH]->(g2) RETURN g1.group_id,g2.group_id, count(u)
This works fine - it creates the relationships and gives me a count of members for each.
My question is: how do I inject that count in the relationship itself?
I tried using 'ON CREATE SET r.members_count = count(u)' but that gives me an error about count() being used in the wrong context.
I tried giving an alias to count() with something like 'WITH count(u) as members' after the MATCH, but that gives me the total count of all members in common across all paths.. not the count for a given path.
I feel I am very close to the answer but the syntax still eludes me.