Graphileon
Graphileon

Reputation: 5385

MATCH on nodes in a two-dimensional COLLECTION in Neo4j / Cypher

In order to limit traversal through a Neo4j graph db, I am collecting scores from a subgraph. Imagine this (simplified)

MATCH (a)-[:r1 {prop1:123}]->()-[]->()-[]->()-[]->(b {prop2:456}) 
WITH b,b.prop2*r1.prop1 as score ORDER BY score DESC LIMIT 10
WITH COLLECT ([b,score]) AS bscore

so far, so good. To avoid the long traversal, I want to limit the next match to the nodes b stored in bscore and sum the scores in bscore[1], but I couldn't find the correct syntax. Even wondering whether it's possible in cypher. Conceptually I'd like to do this:

MATCH bscore[0]-[:r2]->(c)
RETURN c, SUM(bscore[1])

Any hints/ pointers highly appreciated.

Upvotes: 2

Views: 186

Answers (1)

Jacob Davis-Hansson
Jacob Davis-Hansson

Reputation: 2663

Could you do something like this perhaps?

MATCH (a)-[:r1 {prop1:123}]->()-[]->()-[]->()-[]->(b {prop2:456}) 
WITH b,b.prop2*r1.prop1 as score ORDER BY score DESC LIMIT 10
MATCH b-[:r2]->(c)
RETURN c, sum(score)

Upvotes: 2

Related Questions