0
votes

I have a graph database that consists of nodes (bus stations) with a property called “is_in_operation” which is set to “true” if the bus station is operational; otherwise it is set to “false”.

There is a relationship created between two nodes if a bus travels between the two stations.

I would like to find the path with the shortest number of stops between two nodes where all nodes in the path are operational.

There is an example in the database where there are 2 paths between 2 specified nodes. The “is_in_operation” property is set to ‘true’ for all nodes in both paths. When I run the following query, I get the correct answer

START d=node(1), e=node(5) 
MATCH p = shortestPath( d-[*..15]->e ) where all (x in nodes(p) where x.is_in_operation='true')
RETURN p;

When I set the ‘is_in_operation’ property to ‘false’ for one of the intermediate nodes in the shortest path and rerun the query, I expect it to return the other path. However, I get no answer at all.

Is the query incorrect? If so, how should I specify the query?

1

1 Answers

3
votes

The problem is that shortestPath can't take into account the where clause, so you're matching the shortest path, and then filtering it out with your where.

How about this one--it might not be as efficient as shortestPath, but it should return a result, if one exists:

START d=node(1), e=node(5) 
MATCH p = d-[*..15]->e
where all (x in nodes(p) where x.is_in_operation='true')
RETURN p
order by len(p)
limit 1;