Trying to figure out the following scenario.
Setup:
- Used the suggestions in this post to create a Time Tree http://www.markhneedham.com/blog/2014/04/19/neo4j-cypher-creating-a-time-tree-down-to-the-day/
- Extended it to go to the Hour and Minutes (for the sake of simplicity, using 0,15,30,45
- Connected the Minutes with :NEXT (similar to what's done on days, but on minutes)
- Created several events attached to the minutes with "STARTS_AT" and "ENDS_AT"
Goals
- Find all events occurring between two dates
- Find conflicting events (events that overlap)
Attempted the following query:
// Get all events between 2 times
MATCH (m1:Minute { minute: 15 })<--(h:Hour { hour: 8 })<--(d:Day { day: 24 })<--(month:Month { month: 10 })
MATCH (m2:Minute { minute: 45 })<--(h2:Hour { hour: 10 })<--(d2:Day { day: 24 })<--(month2:Month { month: 10 })
MATCH p=((m1)-[:NEXT*]->(m2))
WITH NODES(p) as pnodes UNWIND pnodes AS pwind
MATCH (e:Event)-[:STARTS_AT]->(pwind)
RETURN pwind,e
The results are indeed being retrieved, but noticed that:
- If I try to use "shortestpath" instead of regular path, the query only works for a certain threshold (bizarre, can't explain this). For example, if the timespan is more than 2-3 hours it doesn't work; same applies to multiple days, etc.
- Without using "shortestpath", the performance is TERRIBLE. 25 seconds to return only 2-3 items.
Another variation using where (tried it only for future dates):
// Get all events between 2 times
MATCH (e:Event)
WHERE (:Month { month: 10 })-->(:Day { day: 24 })-->(:Hour { hour: 9 })-->(:Minute { minute: 00})-[:NEXT*]->(:Minute)<--(e)
RETURN e
Results: the performance is even WORSE. 100 seconds to retrieve 1 item.
The way I understand and would like to do this, is by using some sort of function that allows the path to return related nodes. This is: path function returns only the specific node being queried (in this case Minutes), but I would like to bring for ALL THOSE MINUTES, the Events associated by ":STARTS_AT".
Finally, the questions:
- What's the recommended way to perform this query?
- Is this a scenario that is supported by Cypher and neo4j?
- Would it be preferrable to "fall back" to property based time querying instead of trying to attempt graph based time queries?
Thanks in advance.