raj
raj

Reputation: 127

cypher shortestpath query with filter

I am using cypher query for shortest path.

               MATCH path = allshortestPaths((a:Place { Name:'Name-1' })-[*]
               -(b:Place { Name:'Name-2' }))
               WHERE ANY(x IN nodes(path) WHERE x.Status = "true")
               RETURN path

Above query is filtering the paths after getting the list of shortest paths.

But My requirement is it should filter paths internally with ANY(x IN nodes(path) WHERE x.Status = "true") conditions, then among the filtered paths, it should find the shortestpath.

Is this possible?

Upvotes: 0

Views: 475

Answers (1)

Martin Preusse
Martin Preusse

Reputation: 9369

It doesn't matter whether you get all shortest paths first and then filter for a condition or the other way around. As posted in the comment, the condition is used for the shortest path query.

Your query might be slow because all paths have to be evaluated to find the shortest path matching your condition (see link from comment).

If your query runs and returns something you are all good.

Upvotes: 1

Related Questions