Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

neo4j find all paths between nodes. Trek & mountaineering routing

Tags:

neo4j

cypher

I start to learn neo4j. I am using the graph

http://neo4j.com/graphgist/b1f6439d-2904-4fcf-8017-8c83d57ef20b#listing_category=sports-and-recreation

and I have a problem. I do not know how to get all the connections from Darjeeling to Sandakphu. All queries return invalid input or no rows.

Could anyone see how should be build correct query?

1)This is correct

MATCH (p:peak{name:'Sandakphu'})-[r:twowheeler*]-(t:town{name:'Rimbik'}) return distinct(r)

What's wrong with this one if I want all routes

MATCH (p:peak{name:'Sandakphu'})-[r:*]-(t:town{name:'Darjeeling'}) return distinct(r)

2) This is correct

MATCH (a:village { name: 'Sirikhola' }),(b:village{ name: 'Gurdum' }) MATCH (a)-[r]->(b) RETURN r

With this

MATCH (a:village { name: 'Sirikhola' }),(b:town{ name: 'Darjeeling' }) MATCH (a)-[r]->(b) RETURN r

i have no rows

like image 384
wonap Avatar asked Jan 28 '26 20:01

wonap


1 Answers

In the second case, there appears to be no path of length 1 between Sirikhola and Darjeeling, and so the query returns nothing. Try putting a reasonable upper bound for the max hops:

MATCH (a:village{name:'Sirikhola'})-[r*..5]-(t:town{name:'Darjeeling'}) 
return r

The first query should also work (I've added an upper bound instead of leaving it unconstrained):

MATCH (p:peak{name:'Sandakphu'})-[r*..5]-(t:town{name:'Darjeeling'}) 
return r

BTW you can consider using allShortestPaths

like image 71
Luanne Avatar answered Jan 31 '26 06:01

Luanne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!