Mik378
Mik378

Reputation: 22171

Cypher / Preventing shortestPath function to retrieve nodes that don't involve at least one traversed relationship

Regarding this excerpt of cyper request: (assuming element is a known node variable in the whole request)

MATCH p = shortestPath(element-[:LINKS*..3]-(user))
RETURN length(p)

Assuming that one element might be a user, how could I prevent retrieving in the result the element representing the user itself?

It would be cool if we could do:

MATCH p = shortestPath(element-[:LINKS*1..3]-(user))
RETURN length(p)

But it leads to this error:

shortestPath(...) does not support a minimal length

What is the most efficient way to achieve this trick?

Upvotes: 1

Views: 211

Answers (1)

cybersam
cybersam

Reputation: 66989

How about this:

MATCH p = shortestPath((element)-[:LINKS*..3]-(user))
WHERE element <> user
RETURN length(p)

Upvotes: 5

Related Questions