1
votes

i'm trying to model a cypher query for the following scenario:

I have 3 start nodes A, B, C and i'm trying to find n nodes D which are related to all three start nodes. At the end I will reduce the weight property of the relationships and choose the node with the highest weight.

Thanks in advance for helping me out!

1

1 Answers

1
votes

How about something like this?

MATCH (a:Node {name: "A"})-[r1]-(d)
, (b:Node {name: "B"})-[r2]-(d)
, (c:Node {name: "C"})-[r3]-(d)
RETURN d.name
, r1.weight + r2.weight + r3.weight AS Weight
ORDER BY Weight DESC
LIMIT 1

Only return d's that match all of a, b, c; add up the weights of those relative relationships; sort descending by weight; and pick off the first.