I tried and could not do something very similar to this a few days ago. The problem is that you cannot get the amount of the collection, but only the amount of aggregation.
See: https://groups.google.com/d/topic/neo4j/_MqwGp1a1Oo/discussion
I hope they add some features to this in Cypher, but I could not get it to work, even with the help of an expert, Michael Hunder.
UPDATE . I actually in the course of Cypher code today made an expression that does just that. Iβm not sure that it will be adopted at 1.9, but perhaps some form of it will soon enter the community.
UPDATE 2 They merged into my pull request for reduce in 1.9-SNAPSHOT, I will update the syntax below.
Basically this is what you ask for - a slightly outdated version of my data is here: http://console.neo4j.org/r/2rvznu
And here is Cypher ( NOTE, 1.9-SNAPSHOT is currently required ):
START n=node(18) MATCH p=n-[r*]->m WHERE not(m-->()) WITH extract(x in r: x.score) as scores, length(p) as len RETURN scores, reduce(res=0, x in scores: res + x) as totalscore, len ORDER BY totalscore desc;
gives:
+------------------------------------------+ | scores | totalscore | len | +------------------------------------------+ | [0.9,0.9,3.7] | 5.5 | 3 | | [0.8,0.79] | 1.59 | 2 | | [0.4,0.75] | 1.15 | 2 | | [0.4,0.45] | 0.8500000000000001 | 2 | +------------------------------------------+
source share