简体   繁体   English

Neo4j:如何在给定日期范围内按中间日期查询

[英]Neo4j: how to query by intermediate date when given date range

Neo4J TimeTree is an efficient way of modelling time in a graph. Neo4J TimeTree是在图形中建模时间的有效方法。 However, I'm interested in how best to model/query for an object with a defined start and end time. 但是,我对如何最好地对具有定义的开始和结束时间的对象进行建模/查询感兴趣。

For instance, a ticket might be validFrom and validTo given dates, which may be separated by many days. 例如,票证可能是给定日期的有效期自和有效期至,可以相隔很多天。 A user may have many tickets. 用户可能有很多票。

For a given date, what is the most efficient way of querying for valid tickets? 对于给定的日期,查询有效票证的最有效方法是什么?

When entering the data, I suppose I could create lots of validOn relationships between a ticket and the intermediate days between the start and end, but this seems inefficient. 输入数据时,我想我可以在票证与开始和结束之间的中间日期之间创建许多validOn关系,但这似乎效率很低。 Can anyone think of a better way of querying the data? 谁能想到一种查询数据的更好方法?

I can start from a user and find all tickets for that user whose validFrom is <= and validTo is >= the date. 我可以从一个用户开始,找到该用户的所有票证,该用户的validFrom为<=且validTo为> =日期。 However, what happens if I need to start from a date? 但是,如果我需要从日期开始怎么办? Ie match all tickets that are valid on a given date? 即匹配给定日期的所有有效票证?

You only link the ticket to the validFrom and validTo dates with dedicated relationships. 您仅将故障单链接到具有专用关系的有效期起始日期和有效期末日期。

For any given day, you query backwards for tickets that have their :START relationship before that date but the :END relationship after that date, something like this: 对于任何给定的日期,您可以向后查询在该日期之前具有:START关系但在该日期之后具有:END关系的票证,如下所示:

MATCH path = (t:Ticket)-[:START]->(before:Day)-[:NEXT*0..30]->(day:Day {date:{date}})
WHERE (t)-[:END]->(:Day)<-[:NEXT*1..30]-(day)
RETURN t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM