So I am trying return 2 sets from a single cypher query:
Given parent nodes are in the index, then
- children of parent nodes
- childless parent nodes.
I was able to get a similar query that returns parents that are in the index in one set and their children in another set like the following
START Parents = node:app_fulltext('name:"City"'),
MATCH Parents-[?:ChildOf]-Apps
RETURN collect(Apps.Title), collect(Parents.Name);
==> +--------------------------------------------------------------+
==> | collect(Apps.Title) | collect(Parents.Name) |
==> +--------------------------------------------------------------+
==> | ["Empty City 3D"] | ["Empty City 3D","Empty City 3D Fake"] |
==> +--------------------------------------------------------------+
This is close to what I want. However, I want to filter out from Parents.Name those items that already have Children in the Apps.Title collection.
This is the result set I'd like to get. "Empty City 3D Fake" does not have any children so it is returned in Parents.Name.
==> +--------------------------------------------------------------+
==> | collect(Apps.Title) | collect(Parents.Name) |
==> +--------------------------------------------------------------+
==> | ["Empty City 3D"] | ["Empty City 3D Fake"] |
When I just added the Where r is null clause it returned nothing, so I ended up having to add two identical start Parent sets (Parents and Parents2) to do this. However, that looks really cludgy so I was hoping there was a better way.
START Parents = node:app_fulltext('name:"City"'),
Parents2 = node:app_fulltext('name:"City"')
MATCH Parents-[r?:ChildOf]-Children, Parents2-[:ChildOf]-Apps
Where r is null
return collect(Apps.Title), collect(Parents.Name);
==> +--------------------------------------------------------------+
==> | collect(Apps.Title) | collect(Parents.Name) |
==> +--------------------------------------------------------------+
==> | ["Empty City 3D"] | ["Empty City 3D Fake"] |
==> +--------------------------------------------------------------+