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
(collection)[..5] is telling return first 5 elements of collection, collection list in java or array in php example.
Comments
Post a Comment