I'm using a neo4. 4.3.3 community server on an Ubuntu 20.04.3 machine
I have the following problem: I have a set of X and a set of Y object.
So I start with
MATCH (x:X)
MATCH (y:Y)
Now, I need to create a relationship between each X object and Y object (an n*m cartesian product), with some attributes on the relationships, something like the following:
MERGE (x)-[r:IS_REL]->(y)
SET r.a = 0 if ((x.a > 0 AND y.a = 0) OR (x.a = 0 AND y.a > 0))
r.a = (abs(x.a - y.a) * 1.5) else
r.b = 0 if ((x.b > 0 AND y.b = 0) OR (x.b = 0 AND y.b > 0))
r.b = (abs(x.b - y.b) * 1.0) else
I spent a lot of time trying a lot of different approaches, with no success.
I also tried to implement it using apoc.case, but failing.
Try this:
MERGE (x)-[r:IS_REL]->(y)
with x, r, y
FOREACH(ignoreMe IN CASE WHEN ((x.a > 0 AND y.a = 0) OR (x.a = 0 AND y.a > 0)) and r.a = (abs(x.a - y.a) * 1.5) THEN [1] ELSE [] END|
set r.a = 0
)
FOREACH(ignoreMe IN CASE WHEN ((x.b > 0 AND y.b = 0) OR (x.b = 0 AND y.b > 0)) and r.b = (abs(x.b - y.b) * 1.0) THEN [1] ELSE [] END|
set r.b = 0
)
if ((x.a > 0 AND y.a = 0) OR (x.a = 0 AND y.a > 0)) then r.a = 0
else r.a = (abs(x.a - y.a) * 1.5)
if ((x.b > 0 AND y.b = 0) OR (x.b = 0 AND y.b > 0)) then r.b = 0
else r.b = (abs(x.b - y.b) * 1.0)
Is this right?
Can you try this -
MATCH (x:X)
MATCH (y:Y)
MERGE (x)-[r:IS_REL]->(y)
SET r.a = (case when (x.a > 0 AND y.a = 0) OR (x.a = 0 AND y.a > 0) then 0
else abs(x.a - y.a) * 1.5 end),
r.b = (case when (x.b > 0 AND y.b = 0) OR (x.b = 0 AND y.b > 0) then 0
else abs(x.b - y.b) * 1.0 end)