简体   繁体   English

检索日期范围内发生的操作

[英]Retrieve actions that happened in a date range

I have searched an answer for this but haven't got an exact solution. 我已经搜索了一个答案,但没有得到确切的解决方案。

I have a simple application in which I track the items that a person favourites. 我有一个简单的应用程序,我跟踪一个人喜欢的项目。 I create a relationship like so: 我创建了这样的关系:

         [:favorite]
(user) ---------------------> (item)
         timestamp:xxxxxx

The user node gets a favorite relationship to the item, and I store the timestamp as a relationship property. 用户节点获得与项目的最爱关系,并将时间戳存储为关系属性。

There can be several users favoriting the same item, and also one user can favorite several items. 可能有多个用户喜欢相同的项目,并且一个用户也可以喜欢几个项目。 Now, my usecase is to find the items that were favorited in a particular date range, like: 现在,我的用例是查找在特定日期范围内受欢迎的项目,例如:

(1) Items favorited in the last 1 hour (1)过去1小时内收藏的物品

(2) Items favorited between 1st Jan 2015 and 15th Jan 2015 (2)2015年1月1日至2015年1月15日期间收藏的物品

(3) Hour-wise split of items favorited on 15th January 2015 (3)2015年1月15日的小时分割项目

I am trying to find out the most optimized way to return these results. 我试图找出最优化的方法来返回这些结果。 I am using Everyman Neo4j for PHP. 我正在使用Everyman Neo4j for PHP。

My question is how do I index the timestamp property (I believe that would vastly improve performance)? 我的问题是如何索引时间戳属性(我相信这会极大地提高性能)?

Also, what would be an optimal way to structure the queries for the three scenarios listed above? 另外,为上面列出的三种情况构建查询的最佳方法是什么?

Usually you'd model time as a kind of tree or linked list structure in the graph. 通常,您将时间建模为图中的一种树或链表结构。

But for your use-case, you can use a relationship-auto-index to index the timestamp property and then query for it: see: http://neo4j.com/docs/stable/rest-api-configurable-auto-indexes.html 但是对于您的用例,您可以使用relationship-auto-index索引timestamp属性,然后查询它:请参阅: http//neo4j.com/docs/stable/rest-api-configurable-auto-indexes html的

I think it would make sense to choose a format that is easy to search and sort, like yyyy-mm-dd-hh 我认为选择一种易于搜索和排序的格式是有意义的,比如yyyy-mm-dd-hh

change your conf/neo4j.properties to: 将您的conf/neo4j.properties更改为:

relationship_auto_indexing=true
relationship_keys_indexable=timestamp

but you have to re-index existing data, 但你必须重新索引现有数据,

start rel=relationship() start rel = relationship()

and you can query it: 你可以查询它:

start rel = relationship:relationship_auto_index("timestamp:2015-01-*")
match (user)-[rel]->(item)
....

or 要么

start rel = relationship:relationship_auto_index("timestamp:2015-01-*")
return startNode(rel) as user, endNode(rel) as item

Ranges are a not possible with numeric values but with strings. 使用数值但使用字符串是不可能的范围。

start rel = relationship:relationship_auto_index("timestamp:[2015-01-01-00 TO 2015-02-01-00]")
return startNode(rel) as user, endNode(rel) as item

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

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