Query case-specific nodes in neo4j

前端 未结 1 1403
Happy的楠姐
Happy的楠姐 2021-01-23 04:38

I have a setup like the attached image. Orange nodes denotes the cases and the Blue nodes denotes the Performers

1条回答
  •  后悔当初
    2021-01-23 05:14

    As mentionned in the question comment, your calculation should be reversed :

    node j - node i >= 2
    

    One point more, for case 3, Following your explanations there should be a third relationship between node 2 and 3

    Here is a query I made, you can test it in this neo4j console : http://console.neo4j.org/r/gpfesu

    MATCH (n:Case) 
    MATCH path=(pe)<--(n)-->(pe2)
    WHERE pe.name = pe2.name
    AND pe2.id - pe.id >= 2
    WITH path,n, (pe2.id - pe.id) as length
    WITH range(head(nodes(path)).id+1, last(nodes(path)).id-1) as ids,
         n, 
         head(nodes(path)).id as starter,
         length
    UNWIND ids as x
    MATCH (perf:Performer {id:starter})<--(n)-->(perf2:Performer {id:x})
    MERGE (perf)-[:RELATES_TO {value:1, length:length}]->(perf2)
    

    0 讨论(0)
提交回复
热议问题