Reputation: 21
So I have this query in cypher
create (London:Station {name:'London Station'})
create (Bristol:Station {name:'Bristol Station'})
create (Southampton:Station {name:'Southampton Station'})
create (Northampton:Station {name:'Northampton Station'})
create (Brighton:Station {name:'Brighton Station'})
create (Oxford:Station {name:'Oxford Station'})
create (Portsmouth:Station {name:'Portsmouth Station'})
create (Gloucester:Station {name:'Gloucester Station'})
create (London)-[:LEAD_TO {distance:95}]->(Oxford)
create (London)-[:LEAD_TO {distance:52}]->(Brighton)
create (Oxford)-[:LEAD_TO {distance:45}]->(Northampton)
create (Oxford)-[:LEAD_TO {distance:66}]->(Southampton)
create (Brighton)-[:LEAD_TO {distance:49}]->(Portsmouth)
create (Portsmouth)-[:LEAD_TO {distance:20}]->(Southampton)
create (Southampton)-[:LEAD_TO {distance:77}]->(Bristol)
create (Northampton)-[:LEAD_TO {distance:106}]->(Gloucester)
create (Northampton)-[:LEAD_TO {distance:114}]->(Bristol)
create (Gloucester)-[:LEAD_TO {distance:35}]->(Bristol)
The problem I have is: how to find all route between 2 nodes, like node 1 London to node 2 Bristol, help me please
Upvotes: 1
Views: 42
Reputation: 7478
You can search the path between those two nodes:
MATCH p=(London:Station {name:'London Station'})-[:LEAD_TO*]->(Bristol:Station {name:'Bristol Station'})
RETURN reduce(s = "", x IN NODES(p) | s + x.name + " " ), reduce(s = 0, x IN RELATIONSHIPS(p) | s + x.distance )
Upvotes: 1