I'm using Neo4j 2.1.7 and Node.js to build a REST API. The data - around 70.000 nodes and 100.000 relationships - contains very many small connected subgraphs.
One API call, for example localhost:8000/search?name=Bussum
, should return all nodes named Bussum
and the connected component they belong to.
Illustration:
(Image from Wikipedia)
I can get all the data I need with a query like this:
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 just return all triples (a)-[r]-(b)
(not grouped per component/subgraph). Of course, I could reconstruct the graph in Node.js and find the subgraphs myself, but this does not at all feel like the best solution. Is it possible to group the returned data in an array/collection of subgraphs/components? Which Cypher queries would match my use case better? Or should I consider using the Neo4j Java API instead?
Thanks! Bert