Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried and failed to do something very similar to this a few days ago. The problem lies in the fact that you can't get a sum of a collection, only the sum of an aggregation.</p> <p>See: <a href="https://groups.google.com/d/topic/neo4j/_MqwGp1a1Oo/discussion" rel="noreferrer">https://groups.google.com/d/topic/neo4j/_MqwGp1a1Oo/discussion</a></p> <p>I hope they'll add some functionality for this in Cypher, but I couldn't get it to work, even with the help of the expert--Michael Hunger.</p> <p><strong>UPDATE</strong> I actually poked at the Cypher code today to make an expression that does exactly this. I'm not sure if it will be accepted by 1.9, but maybe some form of it will get into the community edition soon. </p> <p><strong>UPDATE 2</strong> They've merged in my pull request for <code>reduce</code> into 1.9-SNAPSHOT, I'll update the syntax below.</p> <p>It does basically exactly what you're asking for--a slightly stale version of my data is here: <a href="http://console.neo4j.org/r/2rvznu" rel="noreferrer">http://console.neo4j.org/r/2rvznu</a></p> <p>And here's the Cypher (<strong>NOTE, currently requires 1.9-SNAPSHOT</strong>):</p> <pre><code> START n=node(18) MATCH p=n-[r*]-&gt;m WHERE not(m--&gt;()) 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; </code></pre> <p>gives:</p> <pre><code>+------------------------------------------+ | 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 | +------------------------------------------+ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload