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.

apoc.combine with apoc.convert.toTree returns multiple trees

MadGraphs
Node

I'm trying to query and return a hierarchy, where I want to be able to specimen the starting node and then get it's children and parents. Querying down children has a specific condition that needs to be met, that querying parents doesn't.

 

MATCH(i:Item {Id: 'some id'})
MATCH (i)-[:BELONGS_TO]->(c:Collection)-[:BELONGS_TO]->(:Project {Name: 'Project A'})
WITH i,c
optional match p1=(i)-[:DERIVED_FROM*]->(:Item)
optional match p2=(x:Item)-[:DERIVED_FROM*]->(i) where exists ((x)-[:BELONGS_TO]->(c))
with apoc.path.combine(p2, p1) AS path
with collect(path) as paths
call apoc.convert.toTree(paths)
YIELD value
RETURN value

 

Say I have a graph that looks like

a -> c
-> d -> e
b -> c          

When I look at the hierarchy for item d, I returned json is a list of 3 different json objects (hierarchies). Seems like it's creating a tree based on the first path (going up from item d), then path from a and then path from b. I get that there will be multiple paths, but shouldn't apoc.convert.toTree combine these correctly?

Looks like p2 is return paths for a->d, b->d, and c->d. As it can't combine leaf nodes, I think the result should be a->d and b->d

 

A simpler example:

 

MATCH(i:Item {Id: '9ccf5efe-50d7-444c-8bbd-578feb861cab'})
MATCH (i)-[:BELONGS_TO]->(c:Collection)-[:BELONGS_TO]->(:Project {name: 'project a'})
WITH i,c
match p1=(i)-[:DERIVED_FROM*]->(:Item)
return p1

 

Say I have a -> b -> c. p1 will be a->b and a->b->c.

1 REPLY 1

MadGraphs
Node

I tried doing top down instead and it's better, but still can't get it quite right.