Cypher q: function to get start/end nodes of relationships?

91 views
Skip to first unread message

Aseem Kishore

unread,
Oct 13, 2012, 10:43:46 AM10/13/12
to Neo4j Discussion
Just like you can dynamically WHERE on the type of a relationship, I thought there was a way to dynamically WHERE on the direction as well -- by comparing the start and end nodes of a relationship.

But neither START(rel) / END(rel) nor rel.start / rel.end work for me, and neither on 1.6 nor on 1.8/9 (whatever's on console.neo4j.org). And looking through the docs, I can't find any mention of these functions.

Is this not implemented yet and my memory was only of a discussion / feature request? Or is it some other name? Thanks!

Aseem

Wes Freeman

unread,
Oct 13, 2012, 10:50:42 AM10/13/12
to ne...@googlegroups.com
There is a feature request for that, I think:

Aseem

--
 
 

Michael Hunger

unread,
Oct 13, 2012, 10:52:47 AM10/13/12
to ne...@googlegroups.com
There is a feature request for that: https://github.com/neo4j/community/issues/693

Also treating relationships as a short path would be a nice thing.
so one can do nodes(r). or head(nodes(r)) tail(nodes(r)).

Michael

--
 
 

Aseem Kishore

unread,
Oct 13, 2012, 10:59:06 AM10/13/12
to ne...@googlegroups.com
Ah cool, thanks guys.

It occurred to me that in the meantime, you could use a pattern WHERE:

MATCH (a) -[r:FOLLOWS]- (b)
WHERE (a) -[r]-> (b)

Cool, at least that's possible. Were pattern WHEREs added in 1.7?

Aseem

--
 
 

Andres Taylor

unread,
Oct 13, 2012, 11:20:39 AM10/13/12
to ne...@googlegroups.com
On Sat, Oct 13, 2012 at 4:59 PM, Aseem Kishore <aseem....@gmail.com> wrote:
Ah cool, thanks guys.

It occurred to me that in the meantime, you could use a pattern WHERE:

MATCH (a) -[r:FOLLOWS]- (b)
WHERE (a) -[r]-> (b)

Hehe... Didn't realise that. Cool! :)

 
Cool, at least that's possible. Were pattern WHEREs added in 1.7?

 No, they made it in in 1.8.

Andrés

Aseem Kishore

unread,
Oct 13, 2012, 11:22:34 AM10/13/12
to ne...@googlegroups.com
Thanks Andrés!

--
 
 

Michael Hunger

unread,
Oct 13, 2012, 11:43:09 AM10/13/12
to ne...@googlegroups.com
actually you can even use 

MATCH p = (a) -[r:FOLLOWS]- (b)
WHERE a = head(nodes(p))

Michael


--
 
 

Andres Taylor

unread,
Oct 13, 2012, 11:48:20 AM10/13/12
to ne...@googlegroups.com
On Sat, Oct 13, 2012 at 5:43 PM, Michael Hunger <michael...@neotechnology.com> wrote:
actually you can even use 

MATCH p = (a) -[r:FOLLOWS]- (b)
WHERE a = head(nodes(p))

Sorry amigo, but that doesn't work. The path always follows the pattern you have described - in this pattern, a will _always_ be a the head of p.  

Andrés

Michael Hunger

unread,
Oct 13, 2012, 12:13:51 PM10/13/12
to ne...@googlegroups.com
Sure I know :)

Was just demonstrating a "true" case

--
 
 

Aseem Kishore

unread,
Oct 13, 2012, 8:35:22 PM10/13/12
to ne...@googlegroups.com
Ah, in my case at least, I'm interested in both directions -- hence not specifying a direction in MATCH. I'm having trouble imagining a case where you *wouldn't* be interested in both directions if you wanted to WHERE on the direction.

(In my case, my WHERE looks something like (direction in AND foo) OR (direction out AND bar).)

Aseem

--
 
 

Wes Freeman

unread,
Oct 14, 2012, 6:11:07 AM10/14/12
to ne...@googlegroups.com
Another use case for this is something like this, match both directions where one direction or foo:
--
 
 

Peter Neubauer

unread,
Oct 14, 2012, 9:13:03 AM10/14/12
to ne...@googlegroups.com
Agreed Wes,
Looks like a very useful addition.
> --
>  
>  
>

--

Cheers,

/peter neubauer

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

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
Reply all
Reply to author
Forward
0 new messages