1
votes

I have a database with nodes (Tiles) connected with relations (Connects). Both tiles and relations have a property called blocked. I would like to get a shortest path between 2 nodes without it containing a blocked node or relation. So when that blocked property is true, that node/relation is not to be used when finding a shortest path. The problem I am struggling with is at the relation when i try to filter them on that property.

For example when I try:

MATCH (node1:Tile {x :1, y :1, blocked:false}),(node2:Tile {x: 2, y: 4, blocked:false}),
p = shortestPath((node1)-[:Connects {blocked:false}]-(node2)) 
RETURN p

I get the error:

shortestPath(...) contains properties MapExpression(List((PropertyKeyName(blocked),False()))). This is currently not supported. (line 2, column 5 (offset: 93))
"p = shortestPath((node1)-[:Connects {blocked:false}]-(node2))"

So my question is: Did I get the cypher wrong, or am I really trying something that is not supported. And ofcourse, what would be the best solution to this puzzle?

1
As the error message is telling you, you cannot currently use properties ({blocked:false}) within the shortestPath call.jonrsharpe
Ok, that means I didn't get the cypher wrong. I will try it without the shortestPath method than. Thanks.Danice

1 Answers

3
votes

This should select all paths which have a "blocked" flag cleared. You'll probably want to tweak the [:Connects*] relationship to a reasonable limit.

MATCH (node1:Tile {x :1, y :1, blocked:false}),
      (node2:Tile {x: 2, y: 4, blocked:false}),
      p = shortestPath((node1)-[:Connects*]-(node2)) 
WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.blocked = FALSE)
RETURN p