Soumya George
Soumya George

Reputation: 29

Cypher query to give path length as a parameter for variable length relationships which is the result of previous sub query

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

Answers (1)

stdob--
stdob--

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

Related Questions