So here's the deal, I'm using Neo4J 3.01 and I have a graph with nodes of type Action which have amongst other links and properties the following two:
Type: [Comment,Reply,Vote etc]
Date:[epoch timestamp]
I am attempting to run a cypher query that returns a sorted list of nodes ordered by the date field but collapsing (Collect?) sequential items of the same type
So for the following nodes:
{type:'Comment',date:1}
{type:'Comment',date:2}
{type:'Vote',date:3}
{type:'Comment',date:4}
{type:'Comment',date:5}
{type:'Reply',date:6}
{type:'Reply',date:7}
{type:'Vote',date:8}
{type:'Vote',date:9}
I would hope to get something like:
{type:'Comment',actions:[{type:'Comment',date:1},{type:'Comment',date:2}]}
{type:'Vote',actions:[{type:'Vote',date:3}]}
{type:'Comment',actions:[{type:'Comment',date:4},{type:'Comment',date:5}]}
{type:'Reply',actions:[{type:'Reply',date:6},{type:'Reply',date:7}]}
{type:'Vote',actions:[{type:'Vote',date:8},{type:'Vote',date:9}]}
I attempted a simple collect and order cypher query:
Match (a:Action)
with a.type as type, a order by a.date limit 20
return type, collect(a) as actions
but this seems to collect each type in its own group regardless of the sequence, so the actual result is something like:
{type:'Comment',actions:[{type:'Comment',date:1},{type:'Comment',date:2},{type:'Comment',date:4},{type:'Comment',date:5}]}
{type:'Vote',actions:[{type:'Vote',date:3},{type:'Vote',date:8},{type:'Vote',date:9}]}
{type:'Reply',actions:[{type:'Reply',date:6},{type:'Reply',date:7}]}
Any Ideas of how to acheive this using cypher? I have tried different means of collect and sorts but to no avail
Any help would be great