I want to create parent nodes (intermediate nodes) for a linked list. In the nodes below, I want a parent node with head at (13) and tail at (17) and another one with head at (17) and tail at (21).
However, when I find the nodes, it creates an extra parent node between (13) and (21) which I do not want.
Here is the code:
//Finding the First Node based on a relationship:
MATCH (a:Alternate)
MATCH (firstnode:Original)
MATCH (firstnode)-[t:ALT]->(a) //a is first Alternate node
CALL
{
WITH a
MATCH (lastnode:Original)
MATCH p = (a)-[:ALT*]->(lastnode)
WITH reduce(output = [], node IN nodes(p) | output + node) as lastNodeCollection, MAX(length(p)) AS max
WITH lastNodeCollection[max] AS last
Return last
}
CALL
{
with firstnode, last
MERGE (last)<-[:LAST]-(v:Parent)-[:FIRST]->(firstnode)
}
Return firstnode, last
Any idea on what I can do to the code to get the desired results?