I'm trying to write a Cypher query for this social network type of application that I'm working on. Just think of a Facebook type of application where you have users who follow other users and the users can write posts and like/share them.
Let's say user Alice follows a couple of people (the subjects).
What the query should return is three things:
I'm able to write the three queries separately:
start alice=node(35500)
match (alice)-[:FOLLOWS]->()-[:SHARES]->(post)
where not((post)-[:ORIGINAL]->())
return post;
start alice=node(35500)
match (alice)-[:FOLLOWS]->()-[:LIKES]->(post)
with post, count(post) as likes
where likes >= 5
return post;
start alice=node(35500)
match (alice)-[:FOLLOWS]->()-[:SHARES]->(post)-[repost:ORIGINAL]->()
with post, count(repost) as reposts
where reposts >= 5
return post;
(a repost has an :ORIGINAL relationship to its original post)
At the moment I'm doing the three queries separately, combining, sorting and paging the results in the client. What I really want is a single query, where I can page the results with SKIP and LIMIT.
As far as I can tell, UNION is not supported in Neo4j 1.9, which is the (stable) version I'm using. Upgrading to an unstable Neo4j 2.0 is not really an option.
Is there a way to do this without Neo4j's UNION?
Thanks!
I think in Neo4j 1.9, you should in that case move to a server plugin or Java code, Cypher doesn't really support this before 2.0.