Need some FILTER help

2,256 views
Skip to first unread message

Chris Bolton

unread,
Aug 17, 2012, 6:37:42 PM8/17/12
to ne...@googlegroups.com
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 

Andres Taylor

unread,
Aug 18, 2012, 4:21:25 AM8/18/12
to ne...@googlegroups.com
On Sat, Aug 18, 2012 at 12:37 AM, Chris Bolton <iknewt...@yahoo.com> wrote:
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)

What is that trying to achieve?

Andrés

Michael Hunger

unread,
Aug 18, 2012, 3:11:19 AM8/18/12
to ne...@googlegroups.com
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, 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.

--
 
 

Chris Bolton

unread,
Aug 18, 2012, 5:06:01 PM8/18/12
to ne...@googlegroups.com
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...@neotechnology.com> wrote:
--
 
 
Reply all
Reply to author
Forward
0 new messages