Let us considered
with [:SUB_CATEGORY] as relationship node
below Cypher query to fetch along with its parts tagged with each nodes
MATCH p=(n:Category)-[:SUB_CATEGORY*]->(m)<-[:TAGGED_TO]-(part:Part)
WHERE NOT ()-[:SUB_CATEGORY]->(n) AND toLower(part.name) STARTS WITH toLower('atm')
WITH COLLECT(p) AS ps
RETURN ps
above cypher query returns actual result set i.e., its showing all relationship both SUB_CATEGORY and TAGGED_TO
Now if I used to convert this into Tree structure using APOC procedure then it skip TAGGED_TO relationship node of Parent Node i.e., Drone
MATCH p=(n:Category)-[:SUB_CATEGORY*]->(m)<-[:TAGGED_TO]-(part:Part)
WHERE NOT ()-[:SUB_CATEGORY]->(n) AND toLower(part.name) STARTS WITH toLower('atm')
WITH COLLECT(p) AS ps
CALL apoc.convert.toTree(ps) YIELD value
RETURN value
Can you give me suggestion for getting the TAGGED_TO node of all nodes along with parent node using APOC
In the first query, the TAGGED_TO
relationship between the parent node Drone
and the :Part
node is shown because the browser option Connect result nodes
is enabled:
If this is checked, after a cypher query result is retrieved, a second query is executed to fetch relationships between result nodes.
But in fact in the result there is no such relationship because match pattern does not take into account the possibility of a path with a long zero. Try this:
MATCH p=(n:Category)-[:SUB_CATEGORY*0..]->(m:Category)<-[:TAGGED_TO]-(part:Part)
WHERE NOT ()-[:SUB_CATEGORY]->(n) AND toLower(part.name) STARTS WITH toLower('atm')
WITH COLLECT(p) AS ps
CALL apoc.convert.toTree(ps) YIELD value
RETURN value