I suggest taking a look at time-based versioning of graphs. http://www.neo4j.org/graphgist?608bf0701e3306a23e77
Also, a thorough blog post on the subject by Ian Robinson, author of the Graph databases book: http://iansrobinson.com/2014/05/13/time-based-versioned-graphs/ Can you provide an example of your results? In your example your timestamp is a string. They should be an integer representation of your datetime, something like unix timestamp milliseconds since epoch. You can also store the date in its long form as a string just for reference. Thanks, Kenny On Wednesday, August 6, 2014 9:36:43 AM UTC-7, Manuel Zamora-Morschhäuser wrote: > > Hello everyone, > > I'm currently designing a cypher query which uses DISTINCT in combination > with aggregations and sorting and I'm not quite sure if I'm doing this the > right way. > > My schema looks like this: > > (user {userId: ..})-[rel:LOVES|HATES|IGNORES|... {timestamp: > ..}]->(something {somethingId: .., additionalSortCriteria: ...}) > > I need a distinct list of Somethings, with only the newest relation of any > type, sorted by the additionalSortCriteria of Something. > > I have for example: > > (user {uid: 1})-[:LOVES {timestamp: "2013-01-01"}]->(something {sid: > 1, additionalSortCriteria: 1}) > (user {uid: 2})-[:LOVES {timestamp: "2013-02-01"}]->(something {sid: > 1, additionalSortCriteria: 1}) > (user {uid: 1})-[:LOVES {timestamp: "2013-03-01"}]->(something {sid: > 2, additionalSortCriteria: 2}) > ... > > I use this query: > > MATCH (user:User)-[rel:LOVES]->(something:Something) > WITH DISTINCT(something.sid) as sid, MAX(rel.timestamp) AS timesort, > MAX(something.additionalSortCriteria) AS somethingsort ORDER BY > somethingsort, timesort > MATCH (user:User)-[rel:LOVES]->(something:Something) WHERE > something.sid=sid AND rel.timestamp=timesort AND > something.additionalSortCriteria=somethingsort > RETURN user,rel,something; > > And get a list of user, relations, somethings with only distinct > somethings, sorted by the somethings.additionalSortCriteria criteria and > only the newest relation... it seems so at least. > > The individual combinations of something.sid and relation.timestamps are > mostly unique, especially in combination with the additionalSortCriteria. > > Did I get it right or have I overlooked something? Is there a better way > to do this? > > > Thank you! > > Manuel > > > -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
