cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Check different conditions on parts of a path depending of type of relationships and labels of nodes

I'm trying to target specific loops in my graph depending on their length and the nature of the nodes and relationships contributing to these loops. My query is still incomplete because I would rely on an "EXISTS" clause in a place it's not allowed to and I'd like ideas for workarounds

Here is part of my cypher code, a bit simplified and abstracted

MATCH 
    p_1 = (a:Adress)<-[:AS_ADRESS]-(e:Etab})<-[:ESTABLISHED]-(s:S),
    p_2 = (a:Adress)<-[:AS_ADRESS]-(b:Building)<-[:IS_OWNER]-(t:Entity),
    p_3 = shortestPath((s:S)-[:R_D|R_M|R_G*1..10]-(t:Entity)) WHERE s<>t
WITH a,e,b, nodes(p_3) as nds, relationships(p_3) as rels
WHERE ALL(
    r IN rels WHERE (
        (
            type(r)='R_D' 
            AND (
                r.prop IS NULL 
                OR r.prop > 37
            )
        ) OR (
            type(r)='R_M' AND NOT startNode(r):Person
        ) OR (
            type(r)='R_M' AND startNode(r):Person AND r.code = 30
        ) OR (
            type(r)='R_G'
)))
RETURN * LIMIT 1000;

As you can see one side of the loop is perfectly described (some entity owns a building, some establishment's address is the address of said building) while the other side of the loop is a path of variable length involving different possible relationships and nodes types with some conditions to apply to the relations of types R_D and R_M.

Now the missing part, is that the condition

 type(r)='R_M' AND startNode(r):Person AND r.code = 30

should be

 type(r)='R_M' AND startNode(r):Person AND r.code = 30 
AND EXISTS {(startNode(r))-[d:R_M{code:30}]-(si:S{act:123456}) WHERE d IN rels OR si IN nds}

which means that the startNode of the relationship r currently examined in the ALL...WHERE clause must be the startNode of a relation (which can be r on another one) which other node has a specific property value and is in the path p3 too

This addition sparks an error because EXISTS can't be part of a ALL (element IN list WHERE) so how could I fit such a condition in my query ?

0 REPLIES 0