Friday, 23 August 2013

neo4j cypher : help on query

neo4j cypher : help on query

I'm having a bit of trouble to design a cypher query.
I have a graph data structures that records some data in time, using
(starting_node)-[:last]->(data1)-[:previous]->(data2)-[:previous]->(data3)->...
Each of the data nodes has a date, and some data as attributes that I want
to sum.
Now, for the sake of the example, let's say I want to query what happened
last week. The closer I got is to query something like
start n= ... // definition of the many starting nodes here
match n-[:last]->d1, path = d1-[:previous*0..7]->dn
where dn.date > some_date_a_week_ago
Unfortunately, as I get the right path, I also get all the intermediate
paths (from 2 days ago, from 3 days ago...etc).
Since there is many starting nodes, and thus many possible path lengths, I
cannot ask for the longest path in my query. Furthermore, dn.date can be
different from date_a_week_ago ( if there is only one data node this week,
and one data node last month, then the expected path is of length=1).
Any tip on how to filter the intermediate paths in my query ?
Thanks in advance !
ps : by the way, I'm quite new with the graph modeling, and I'd be
interested with any answer that would require to change the graph
structure if needed.

No comments:

Post a Comment