Search code examples
neo4jcyphertimeline

Creating timeline: how to get next event?


I found the wiki page about creating time lines but it is very short and incompleted. I managed to create cypher code for adding events to the timeline:

MERGE (y:YEAR{year: {y} })
CREATE UNIQUE y-[:HAS_MONTH]->(m:MONTH{month:{m}    })
CREATE UNIQUE m-[:HAS_DAY]->  (d:DAY  {day:  {d}    })     
CREATE UNIQUE d-[:HAS_EVENT]->(e:EVENT{desc: {desc} })
WITH y AS y
MATCH n RETURN n

It seems to work OK but I also need to be able for any event to get next one. I'm not sure how can I establish horizontal (i.e. between months, days, events) links in cypher and If I manage to do it I will need to destroy this links when I insert a new event between two other events. If I don't establish horizontal links the code to get next event in timeline will be rather awkward I think. Or not? What is the best way too implement it?


Solution

  • Please take a look at How to filter edges by time stamp in neo4j?

    The modeling guideline for time is to use time tree hierarchies for aggregations (Year)->(Month)->(Day), timestamps for ranges, and linked lists for retrieving relative N nodes from any other node (get last 5, get next 5).

    Timeline with linked list