Re: Help with this cypher query

47 views
Skip to first unread message

Stefan Armbruster

unread,
Jul 27, 2012, 6:44:41 AM7/27/12
to ne...@googlegroups.com
According to http://docs.neo4j.org/chunked/milestone/query-match.html#match-match-with-or there is no OR in MATCH. But you could probably use

start startNode = node(3131) match finalNode1<-[:r3?]-middleNode<-[:r2*]-startNode<-[:r1?]-finalNode2 return collect([finalNode1, finalNode2])

Regards,
Stefan

Am Freitag, 27. Juli 2012 09:05:26 UTC+2 schrieb vmarcinko:
Hello,

I've been struggling to solve this cypher query, if possible at all.

I want to return final nodes (finalNode) from my cypher query. And there are 2 ways one can find final nodes in db:

startNode <-[:r1]-finalNode
(when finalNode is directly connected to startNode)
...and...
startNode -[:r2*]->middleNode-[:r3]->finalNode
(when finalNode is connected to middleNode, and this one is connected directly to startNode or to "parent" middleNode)

Both of these queries return finalNodes correctly, but I dunno how to connect them together for purpose of returning final nodes regardless in which way they are connected to start node.

I tried connecting tha match portion with comma, but it doesn't work :

start startNode = node(3131) match startNode <-[:r1]-finalNode , startNode -[:r2*]->middleNode-[:r3]->finalNode return finalNode

Any help?

regards,
Vjeran

vmarcinko

unread,
Jul 28, 2012, 2:19:28 AM7/28/12
to ne...@googlegroups.com
Hi again,

First of all, thanx. 

From Neo4j docs example, my problem is that I want for node (3) (Anders) to find out all the poeple that he KNOWS, or he BLOCKS.

I'm very close to answer, the problem is that nodes are not distinct, so I have duplicates:
start a=node(3) match x1-[?:KNOWS]-a-[?:BLOCKS]->x2 return collect([x1,x2])
Here is a link to try it out:
The result should contain 3 nodes, but it returns duplicate, so I have 4.

I have hoped initially that simplier query would be enough, but it doesn't return correct nodes (only 1):
start a=node(3) match a-[?:KNOWS]-x<-[?:BLOCKS]-a return x

Regards,
Vjeran

Stefan Armbruster

unread,
Jul 28, 2012, 8:27:57 AM7/28/12
to ne...@googlegroups.com


Am Samstag, 28. Juli 2012 08:19:28 UTC+2 schrieb vmarcinko:
Hi again,

First of all, thanx. 

From Neo4j docs example, my problem is that I want for node (3) (Anders) to find out all the poeple that he KNOWS, or he BLOCKS.

I'm very close to answer, the problem is that nodes are not distinct, so I have duplicates:
start a=node(3) match x1-[?:KNOWS]-a-[?:BLOCKS]->x2 return collect([x1,x2])
Here is a link to try it out:
The result should contain 3 nodes, but it returns duplicate, so I have 4.
The problem is that collect does not flatten nested collections. If it did, we could use distinct to filter out duplicates.
 

I have hoped initially that simplier query would be enough, but it doesn't return correct nodes (only 1):
start a=node(3) match a-[?:KNOWS]-x<-[?:BLOCKS]-a return x
This only returns results if both ends refer to the very same node.

Cheers,
Stefan
Reply all
Reply to author
Forward
0 new messages