How to match repeating sub-paths in Cypher

168 views
Skip to first unread message

Daniel Cox

unread,
Mar 14, 2012, 8:56:26 AM3/14/12
to ne...@googlegroups.com
Hey All,

You know how you can get paths of different lengths from this?:
match path = (startnode)-[:REL*]->()
 
I'd like to do the same thing, but i need more than just a single relationship to repeat:
match path = (startnode)-{[:FIRST_REL]->()-[:SECOND_REL]->()}*
 
I'm just making up syntax there.^ The essential thing is that i need to repeat the section of the path "-[:CONTAINS]->()-[:RELATES_TO]->()" multiple times.
Is this possible?

Thanks!
-Daniel

PS: The freenode IRC channel isn't too lively as of late.


Peter Neubauer

unread,
Mar 14, 2012, 9:03:26 AM3/14/12
to ne...@googlegroups.com
Daniel,
you could do

http://docs.neo4j.org/chunked/snapshot/query-where.html#where-filtering-on-relationship-type
which means

match path = (startnode)-[e:*]->() where type(r) =~ /FIRSTREL|SECONDREL/

with regexp, or direct

match path = (startnode)-[e:*]->() where type(r) = "FIRSTREL" OR
type(r)="SECONDREL"

or something along these lines.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Andres Taylor

unread,
Mar 14, 2012, 12:25:33 PM3/14/12
to ne...@googlegroups.com
On Wed, Mar 14, 2012 at 1:56 PM, Daniel Cox <danie...@gmail.com> wrote:
You know how you can get paths of different lengths from this?:
match path = (startnode)-[:REL*]->()
 
I'd like to do the same thing, but i need more than just a single relationship to repeat:
match path = (startnode)-{[:FIRST_REL]->()-[:SECOND_REL]->()}*
 
I'm just making up syntax there.^ The essential thing is that i need to repeat the section of the path "-[:CONTAINS]->()-[:RELATES_TO]->()" multiple times.
Is this possible?

Sorry, Daniel, but that is not supported. It's a good idea, and it really should be supported.

Andrés 

James Thornton

unread,
Mar 14, 2012, 12:35:09 PM3/14/12
to ne...@googlegroups.com


On Wednesday, March 14, 2012 6:56:26 AM UTC-6, Daniel Cox wrote:

PS: The freenode IRC channel isn't too lively as of late.


I didn't realize there is an IRC channel :-\

- James

Peter Neubauer

unread,
Mar 14, 2012, 12:37:26 PM3/14/12
to ne...@googlegroups.com

Yeah,
We haven't been hanging out there lately, mostly because of one more channel being open, that one with bad logging possibility.

Who is interested in having more active conversation there again?

Daniel Cox

unread,
Mar 27, 2012, 1:05:35 PM3/27/12
to ne...@googlegroups.com
OK, thanks for that. I also notice that the syntax for this has been cleaned up a bit in 1.7m2.

As to the irc channel, I'd definitely enjoy an occasional conversation there. :) Perhaps is logging is an issue someone could host a logger bot?
-Daniel

Peter Neubauer

unread,
Mar 30, 2012, 10:16:19 AM3/30/12
to ne...@googlegroups.com
Daniel,
if you wanna hang out, we are having our next community hangout in 2
weeks, see http://www.meetup.com/graphdb-world/

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j                                - Graphs rule.
Program or be programmed - Computer Literacy for kids.
http://foocafe.org/#CoderDojo

Reply all
Reply to author
Forward
0 new messages