title: Loops in cypher
body: <p>The following algorithm finds the page rank (note that this is a tweaked version of page rank algorithm):</p>
  
  <pre><code>/* we have to go through all nodes */
  MATCH (node:Page)
  WITH
  COLLECT(distinct node) AS pages
  UNWIND pages as dest
    /* let's find all source citations for a given node */
    MATCH (source:Page)-[:NEXT]-&gt;(dest)
    WITH
      COLLECT(DISTINCT source) AS sources,
      dest AS dest
      UNWIND sources AS src
        /* we have to know how many relationships the source node has */
        MATCH (src)-[r:NEXT]-&gt;(dest)
        WITH src, dest, sum(r.weight) AS prob
        MATCH (src)-[r:NEXT]-&gt;()
        WITH
        /* The source citation will pass a portion of its pagerank as juice */
          src.pagerank * (prob/ sum(r.weight)) AS juice,
          dest AS dest
        /* now we have all information to update the destination node with the new pagerank */
        WITH
          sum(juice) AS p,
          dest AS dest
        /* Using damping factor d = 0.85 */
        set dest.pagerank = 0.15 + 0.85 * p;
  </code></pre>
  
  <p>Now for a given graph:</p>
  
  <pre><code>LOAD CSV WITH HEADERS FROM "file:\\graphUnioned1.csv" AS csvLine 
  MERGE (s:Node {value:csvLine.s}) 
  MERGE (o:Node {value:csvLine.o}) 
  MERGE (s)-[:REL {weight: toFloat(csvLine.p)}]-&gt;(o);
  </code></pre>
  
  <p>How do I find the page rank of all nodes in the graph. I want to run the above pagerank algorithm iteratively till 100 iterations</p>