I've got a query that returns two collection (friends and outer). Is it possible to filter friends with outer?
Here is my query:
START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) RETURN friends, collect(distinct y) as outer
I'm thinking of something like this:
START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) WITH n, collect(distinct y) as outer, friends RETURN collect(friends + outer) as stuff filter(outer in coll:friends)
At this point, this doesn't work. Is there a way to generate two collections and filter one by the other? Any help would be appreciated even if it's just some example of filter in use or a brief explanation. I'm a little confused on the syntax.
Thanks.
Chris
> I've got a query that returns two collection (friends and outer). Is it
> possible to filter friends with outer?
> Here is my query:
> START n=node(127)
> MATCH(n)-[:friends]->(x)
> WITH n, collect(distinct x) as friends
> MATCH(n)-[:outer_only_friends]->(y)
> RETURN friends, collect(distinct y) as outer
> I'm thinking of something like this:
> START n=node(127)
> MATCH(n)-[:friends]->(x)
> WITH n, collect(distinct x) as friends
> MATCH(n)-[:outer_only_friends]->(y)
> WITH n, collect(distinct y) as outer, friends
> RETURN collect(friends + outer) as stuff filter(outer in coll:friends)
The first part of your return shouldn't be too difficult - you can
concatenate two collections with the plus symbol:
RETURN friends + outer as stuff
The last part I don't understand - filter(outer in coll:friends)
this should work but it doesn't really make sense to me (the use-case).
> START n=node(127) > MATCH(n)-[:friends]->(x) > WITH n, collect(distinct x) as friends > MATCH(n)-[:outer_only_friends]->(y) > WITH n, collect(distinct y) as outer, friends
> RETURN filter(x in outer + friends : x in friends)
PS: You gained quite a lot of cypher knowledge these past weeks, would it be possible for you to write up a blog post explaining the different things, so that others can benefit from that too? That would be awesome.
> I've got a query that returns two collection (friends and outer). Is it possible to filter friends with outer?
> Here is my query:
> START n=node(127) > MATCH(n)-[:friends]->(x) > WITH n, collect(distinct x) as friends > MATCH(n)-[:outer_only_friends]->(y) > RETURN friends, collect(distinct y) as outer
> I'm thinking of something like this:
> START n=node(127) > MATCH(n)-[:friends]->(x) > WITH n, collect(distinct x) as friends > MATCH(n)-[:outer_only_friends]->(y) > WITH n, collect(distinct y) as outer, friends > RETURN collect(friends + outer) as stuff filter(outer in coll:friends)
> At this point, this doesn't work. Is there a way to generate two collections and filter one by the other? Any help would be appreciated even if it's just some example of filter in use or a brief explanation. I'm a little confused on the syntax.
I will work on putting together a blog post. I appreciate everyone's help in getting me this far.
I know the use case looks goofy. This is just a smaller example of my ultimate use case. Hopefully when I build it in console it will come out clearer.
Chris
--- On Sat, 8/18/12, Michael Hunger <michael.hun...@neotechnology.com> wrote:
From: Michael Hunger <michael.hun...@neotechnology.com>
Subject: Re: [Neo4j] Need some FILTER help
To: neo4j@googlegroups.com
Date: Saturday, August 18, 2012, 12:11 AM
Chris,
this should work but it doesn't really make sense to me (the use-case).
START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) WITH n, collect(distinct y) as outer, friendsRETURN filter(x in outer + friends : x in friends)
PS: You gained quite a lot of cypher knowledge these past weeks, would it be possible for you to write up a blog post explaining the different things, so that others can benefit from that too? That would be awesome.
Am 18.08.2012 um 00:37 schrieb Chris Bolton:
I've got a query that returns two collection (friends and outer). Is it possible to filter friends with outer?
Here is my query:
START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) RETURN friends, collect(distinct y) as outer
I'm thinking of something like this:
START n=node(127) MATCH(n)-[:friends]->(x) WITH n, collect(distinct x) as friends MATCH(n)-[:outer_only_friends]->(y) WITH n, collect(distinct y) as outer, friends RETURN collect(friends + outer) as stuff filter(outer in coll:friends)
At this point, this doesn't work. Is there a way to generate two collections and filter one by the other? Any help would be appreciated even if it's just some example of filter in use or a brief explanation. I'm a little confused on the syntax.
Thanks.
Chris