title: Match FOAF, but constrain path by date; specifically in a sequential manner, in Neo4j
body: <p>I am doing a 'friend of a friend'-type MATCH in Neo4j. The only thing about it that is throwing me off is an attempt to constrain all the relationships by date.</p>
  
  <p>The basic graph is like so:  </p>
  
  <p><a href="https://i.stack.imgur.com/jEkdH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jEkdH.png" alt="enter image description here"></a></p>
  
  <p>The 'real' version of the graph has 10 1st degree friends, and 3385 2nd degree friends.</p>
  
  <p>And although I didn't put a date property on each edge on the image above, indeed that is the case. There is no order to any of the dates.  </p>
  
  <p>The general idea is pretty straightforward: I would like make sure to disregard any relationship that has a date property which is older than a predetermined maximum date.  </p>
  
  <p>The slightly tricky part is, that if the maximum date constraint is violated within the first relationship (like on one the three edges that come off the node in the image above), then that edge is broken in half and no other traversal down that path should be able to occur. (e.g., I don't want any of the leaf nodes).  </p>
  
  <p>I wrote this:  </p>
  
  <pre><code>MATCH
  (n)-[f1:FRIEND]-()-[f2:FRIEND]-(m)
  WITH n, m,split('1962-1-1', '-') AS maxdate
  WHERE n.person_id='180'
  AND(
  (
  toInt(maxdate[0]) &gt; toInt(split(f1.date, '-')[0])
  )   
  OR
  (
  toInt(maxdate[0]) = toInt(split(f1.date, '-')[0])
   AND
  toInt(maxdate[1]) &gt;= toInt(split(f1.date, '-')[1])
  ))
  AND(
  (
  toInt(maxdate[0]) &gt; toInt(split(f2.date, '-')[0])
  )   
  OR
  (
  toInt(maxdate[0]) = toInt(split(f2.date, '-')[0])
   AND
  toInt(maxdate[1]) &gt;= toInt(split(f2.date, '-')[1])
  ))
  RETURN m;
  </code></pre>
  
  <p>This code block ran for about 20 minutes and eventually appears to have resulted in something close to what I was aiming for.  Here's what it looks like in the browser:  </p>
  
  <p><a href="https://i.stack.imgur.com/XfSfy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XfSfy.png" alt="enter image description here"></a></p>
  
  <p>(It has 350 nodes)</p>
  
  <p>First, I'll admit that this is clearly some terribly written code (both in terms of aesthetics and performance). Second, I'm noticing the unassociated nodes on the perimeter.  </p>
  
  <p>What I think happened, is when the first degree relationship's date condition fails, but the second degree relationship's doesn't, and so I'm ending up with the 'friend of a friend' that I don't want to be included.  </p>
  
  <p>How can I modify my date condition such that I eliminate these free-standing nodes when the first degree edge is invalidated?</p>
  
  <p>If anyone has any insight I would greatly appreciate it. (Not to get too mushy, but thanks to the SO community, I've already come relatively far pretty quickly, and for that I'm grateful.)</p>