cypher - Limit Subnodes Performance in Neo4j -


i writing cypher output of 5 product per category cypher:

match (s:supplier)-[:post]->(p:product)-[:belong_to]->(c:category)  * match r = (c)<-[:belong_to*0..5]-(p) c, collect(tail(nodes(r))) allcatproducts return c, reduce(outputproducts=allcatproducts[..0] , catproduct in allcatproducts | outputproducts + catproduct)[..5]; 

however, performance of cypher poor. there did wrong here?

also, trying understand part:

[:belong_to*0..5] 

and

(catproduct)[..5] 

any appreciated.

you seem overcomplicate query, query should job :

match (s:supplier)-[:post]->(p:product)-[:belong_to]->(c:category) return c.name, collect(p)[..5] products 

concerning other question :

(x)-[r:belong_to*0..5]->(y) 

is variable length path query, here should aware if no y node found, x returned y

http://neo4j.com/docs/stable/query-match.html#_relationships_in_depth

http://graphaware.com/graphaware/2015/05/19/neo4j-cypher-variable-length-relationships-by-example.html


(collection)[..5] 

is telling return first 5 elements of collection, collection list in java or array in php example.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -