Reputation: 29
For the following cypher query , how to limit path length by giving "cnt" as a parameter which is the output of previous query passed to next query using "with" clause.
match ()-[r:contents|next_seq]->(n:word) where r.seqid={seqid}
with count(distinct n) as cnt
match p=((a:word)-[rels:next_seq*cnt]->(b:word))
WHERE ALL( rt in rels WHERE rt.seqid={seqid}
return b.name
Upvotes: 0
Views: 429
Reputation: 29172
At this time, the cypher
does not allow to use a variable as the path length.
If you use a version of neo4j
>= 3 you can use apoc path expander
:
match ()-[r:contents|next_seq]->(n:word) where r.seqid={seqid}
with count(distinct n) as cnt
match (a:word)-[rels:next_seq {seqid: {seqid}}]->(:word))
with distinct a
call apoc.path.expand( a, 'next_seq', '+word', 1, cnt ) yield path
with path WHERE ALL( rt in relationships(path) where rt.seqid={seqid} )
return last(nodes(path)).name as name
Upvotes: 2