Reputation: 1606
I am trying to solve this problem but still it has problem.. Well, my query a bit complex because I use extract, shortpath and filter. When I try this code below, It returns filter requires where..
match (actor:Actor{name:"XXXX"}),(reeves:Actor{name:"YYYY"}),
p= shortestPath ((actor)-[*..20]-(reeves))
where "Reeves, Keanu"=filter(n2 in nodes(p):n.name)
return distinct extract(n in nodes(p)|n.name) as Names;
but as you see there is "where" keyword.
and I tried like that
match (actor:Actor{name:"XXXX"}),(reeves:Actor{name:"YYYY"}),
p= shortestPath ((actor)-[*..20]-(reeves))
WHERE NOT ALL (x IN nodes(p)
WHERE x.name<> "YYYY")
return distinct extract(n in nodes(p)|n.name) as Names;
but this time, I still get "Reeves, Keanu" name.. I want to filter this name from my result..
where am I doing a mistake?
Upvotes: 0
Views: 1992
Reputation: 66999
If you want to find the shortest paths that contain the name "YYYY", try:
MATCH (actor:Actor{name:"XXXX"}), (reeves:Actor{name:"YYYY"}),
p = shortestPath ((actor)-[*..20]-(reeves))
WHERE any(n2 in nodes(p) WHERE n2.name="YYYY")
RETURN distinct extract(n in nodes(p) | n.name) as Names;
On the other hand, if you want to ignore the shortest paths that contain the name "YYYY":
MATCH (actor:Actor{name:"XXXX"}), (reeves:Actor{name:"YYYY"}),
p = shortestPath ((actor)-[*..20]-(reeves))
WHERE none(n2 in nodes(p) WHERE n2.name="YYYY")
RETURN distinct extract(n in nodes(p) | n.name) as Names;
By the way, notice how the any
and none
predicates internally require a WHERE clause
.
Upvotes: 2