cancel
Showing results for 
Search instead for 
Did you mean: 

Find the shortest path where end is

Please keep the following things in mind:

Hello everybody, I have a such issue:
I need to find such path where I know everything about start but don't know anything about end
BUT i know that it has to be something that apply some conditions. Let's look at this cypher:
match (start:NodeCell)
where id(start)=162
match west=shortestPath((start)-[c:Connected*]->(end:NodeCell))
where all(r in relationships(west) where r.DIRECTION="WEST") and (end.figureId < 0 or end.house<>start.house or not exists((end)-[:Connected{DIRECTION:"WEST"}]->()))
return distinct west;

  1. All relationshps has to have direction:WEST
  2. End may has got figureID < 0 or end.house<>start.house(house is a boolean value) or it can be the leaf
  3. Why do i find the shortest way? Because if I found the end which has figureId< 0 or (second condition) I have to stop. The end has to be the first cell which ive meat on this way with this conditions.
    It works too slowly and im not sure that it works at all..
    Help please, thank)
1 ACCEPTED SOLUTION

koji
Ninja
Ninja

Hi @dimachichlov

Two suggestions.

  1. Add limit the hop like this.
MATCH west=shortestPath((start)-[c:Connected*..30]->(end:NodeCell))
  1. Add the indexes to the relationship properties.
    Indexes for search performance - Neo4j Cypher Manual

View solution in original post

1 REPLY 1

koji
Ninja
Ninja

Hi @dimachichlov

Two suggestions.

  1. Add limit the hop like this.
MATCH west=shortestPath((start)-[c:Connected*..30]->(end:NodeCell))
  1. Add the indexes to the relationship properties.
    Indexes for search performance - Neo4j Cypher Manual