(cross-posting from SO)
I'm trying to get all vertices up to a certain maximum cumulative weight (distance) from a specific node. The query
MATCH route = (p1:ReferencePlace) - [roadlist:EROAD*..5] - (p2:ReferencePlace) WITH p1, p2, route, roadlist, REDUCE(sum=0.0, road in roadlist | sum + toFloat(road.distance)) as totaldistance WHERE totaldistance < 300 AND p1.name = "Paris" RETURN p1, p2, totaldistance
produces the right output. This uses the E-road data example imported like here. It returns all places which are less than 300 km from Paris.
The problem is, that this only works for a limited number of hops
EROAD*] it "hangs" (I don't know whether it would finish in any reasonable amount of time). This is because Neo4j first finds all possible routes and then filters them. Therefore, it makes sense that the number of routes gets infeasibly large even for a small graph like this.
In theory it would be no big deal to implement a BFS algorithm from scratch which just gathers all relevant vertices as long as long as the cumulative distance is smaller than the threshold and only visits the relevant ones. But I'm wondering whether there's a Neo4j way of doing this.