neo4j - auto multi-level tree with cypher -



neo4j - auto multi-level tree with cypher -

i'm having neo4j schema: 1 node linked relationship "contents". let's don't know how much levels have.

for now, have query :

match (p:keyword) optional match (p)-[:contents]->(p1) optional match (p1)-[:contents]->(p2) optional match (p2)-[:contents]->(p3) optional match (p3)-[:contents]->(p4) p,p1,p2,p3,{uid: p4.uid, name: p4.name} child4 p,p1,p2,{uid: p3.uid, name: p3.name , children: collect(child4)} child3 p,p1,{uid: p2.uid, name: p2.name , children: collect(child3)} child2 p,{uid: p1.uid, name: p1.name , children: collect(child2)} child1 {uid: p.uid, name: p.name, children: collect(child1)} kid homecoming {tree: collect(child)}

the results need way, limit results 5 levels. without adding more "optional match", how can set query automatically multi-level ?

thanks help :)

don't understand desired output of query should be.

you need utilize variable path length match amending relationship specification quantifier *<lower>..<upper>:

match path=(p:keyword)-[:contents*0..5]->(content) // match 0 5 contents hops homecoming path, length(path) len order len desc limit 1 // proceed longest path

edit:

match path=(p:keyword)-[:contents*0..4]->(content)-[:contents]->(child) homecoming content.uid, collect(child.uid) children

tree neo4j cypher

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -