I am using Neo4j 2.1.7 and Node.js to create a REST API. The data - about 70,000 nodes and 100,000 relationships - contains a lot of small related subgraphs.
One API call, for example localhost:8000/search?name=Bussum , should return all nodes with the name Bussum and the associated component to which they belong.
Illustration:

(Image from Wikipedia )
I can get all the data I need with this request:
MATCH (a {name: "Bussum" })-[r*]-(b) UNWIND rels AS rel RETURN distinct startNode(rel) AS a, type(rel), endNode(rel) AS b
But such a query will simply return all triples (a)-[r]-(b) (not grouped by component / subgraph). Of course, I could restore the graph in Node.js and find the subgraphs myself, but this does not seem like the best solution. Is it possible to group the returned data in an array / collection of subgraphs / components? Which Cypher queries will best suit my use case? Or should I use the Neo4j API instead?
Thanks! Bert
source share