Re: [Neo4j] Cypher returning values from two match queries as one result

Showing 1-9 of 9 messages
Re: [Neo4j] Cypher returning values from two match queries as one result Michael Hunger 10/30/12 5:10 PM
Try to use better identifier-names :)

In general you can use collect:

return collect(b) as user_posts, collect(d) as other_posts

if you want to combine them

return collect(b) + collect(d) as posts

Am 31.10.2012 um 00:20 schrieb Aran Mulholland <aranmul...@gmail.com>:

I have a simple social network graph db model. Users can follow other users and post posts. I am trying to get a list of all posts that a user has posted along with any that anyone the user follows has posted

START a=node:node_auto_index(UserIdentifier = "USER0") 
MATCH (a)-[:POSTED]->(b), (a)-[:FOLLOWS]->(c)-[:POSTED]->(d) 
RETURN b, d;

It is returning the cross product of the two, a tuple of all the values in b joined with all the values in d. (b x d) I would like just a straight list of posts. How do I do this? Do I need to do two separate queries?


Neo4j 1.8RC1, Windows, Java 7


--
 
 

Re: [Neo4j] Cypher returning values from two match queries as one result Aran Mulholland 10/30/12 6:01 PM
Thanks Michael,

So the query: (with better identifier names:)

START me=node:node_auto_index(UserIdentifier = "USER0")
MATCH (me)-[:POSTED]->(myposts),
(me)-[:FOLLOWS]->(friends)-[:POSTED]->(myfriendsposts)
RETURN collect(myposts) + collect(myfriendsposts) as posts;

Should work? Because this never returns. The console just sits there,
dreaming perhaps.

Also do I need the "as posts"?
> --
>
>
Re: [Neo4j] Cypher returning values from two match queries as one result Michael Hunger 10/30/12 6:34 PM
What's your datasize?

> RETURN count(myposts) + count(myfriendsposts) as posts;
> --
>
>

Re: [Neo4j] Cypher returning values from two match queries as one result Aran Mulholland 10/30/12 6:51 PM
1215 nodes 660 properties 1809 relationships.

(so not big, i must be doing something else that's silly)
> --
>
>
Re: [Neo4j] Cypher returning values from two match queries as one result Aran Mulholland 10/31/12 11:09 PM
If I read the doco properly the collect operator returns all nodes as
a single row.
Is there another way that returns a set of rows that are the collected
by following two different paths?

Is there a Cypher function that breaks the return value of collect
into separate values?

Thanks

Aran.
Re: [Neo4j] Cypher returning values from two match queries as one result Wes Freeman 10/31/12 11:12 PM
I have a feature request for breaking up collections in github. https://github.com/neo4j/community/issues/898

--



Re: [Neo4j] Cypher returning values from two match queries as one result Michael Hunger 10/31/12 11:37 PM
I mean the number of followed paths.


You can use the collection created by collect twice with filter with 2 different conditions

Sent from mobile device
> --
>
>
Re: [Neo4j] Cypher returning values from two match queries as one result Andres Taylor 11/1/12 1:56 AM
Hi Aran,

This is how MATCH is supposed to work. If you need two collections, one with all the posts by the user, and one with all the posts of his followers, I would recommend you do it like this:

START a=node:node_auto_index(UserIdentifier = "USER0") 
MATCH (a)-[:POSTED]->(b)
WITH collect(b) as posts
MATCH (a)-[:FOLLOWS]->(c)-[:POSTED]->(d) 
RETURN posts, collect(d) as followersPosts;

HTH,

Andrés

On Wed, Oct 31, 2012 at 12:20 AM, Aran Mulholland <aranmul...@gmail.com> wrote:

I have a simple social network graph db model. Users can follow other users and post posts. I am trying to get a list of all posts that a user has posted along with any that anyone the user follows has posted

START a=node:node_auto_index(UserIdentifier = "USER0") 
MATCH (a)-[:POSTED]->(b), (a)-[:FOLLOWS]->(c)-[:POSTED]->(d) 
RETURN b, d;

It is returning the cross product of the two, a tuple of all the values in b joined with all the values in d. (b x d) I would like just a straight list of posts. How do I do this? Do I need to do two separate queries?


Neo4j 1.8RC1, Windows, Java 7

--
 
 



--
The best way to ask for Cypher help: http://console.neo4j.org/usage.html 

Re: [Neo4j] Cypher returning values from two match queries as one result Andres Taylor 11/1/12 2:01 AM
Sorry, I messed up. You need to pass on a through WITH as well.

START a=node:node_auto_index(UserIdentifier = "USER0") 
MATCH (a)-[:POSTED]->(b)
WITH a, collect(b) as posts
MATCH (a)-[:FOLLOWS]->(c)-[:POSTED]->(d) 
RETURN posts, collect(d) as followersPosts;