0
votes

I have some linked list structure:

(post:Post)-[:NEXT]->(next_post:Post)-[:NEXT]->....

I can query it by simple statement:

MATCH (start:Post{Id:{post}})-[:NEXT*0..19]->posts
RETURN posts

It returns 20 posts in response.

But if my query is like that:

MATCH (start:Post{Id:{post}})-[:NEXT*0..19]->post
WHERE not post:Deleted
RETURN posts

then I will certainly not get 20 posts (i.e. if I have 3 posts with :Deleted label, then I will get 17 posts)

How can I achieve fixed length of variable path with some conditions?

In total, I want to get same fixed amount of nodes in variable length path with upper bound despite of predicates. Something like that:

MATCH (start:Post{Id:{post}})-[rels:NEXT*0..]->post
WHERE ANY (rel IN rels WHERE NOT ENDNODE(rel):Deleted)
RETURN post

but with upper limit of traversal.

1
Could you please rephrase your question? I am unable to tell what you want to know. - Jim Biard

1 Answers

1
votes

Filter out the deleted posts beforehand:

MATCH (posts:Post)
WHERE NOT posts:Deleted
WITH posts
MATCH (start:Post{Id:{post}})-[:NEXT*0..19]->(posts)
RETURN posts