Cypher and shortestPath

210 views
Skip to first unread message

BtySgtMajor

unread,
Oct 1, 2012, 12:26:24 PM10/1/12
to ne...@googlegroups.com
Hi all,

  I'm curious as to what the return type for the Cypher match function "shortestPath" is.  Is "Path" an actual return type?  I'm only asking because I'm looking to divide up the result (since "shortestPath" only returns a single value) into a multi-row result set that details the nodes and relationships traversed.  Or, perhaps SDN has a way to simply parse the result into the necessary POJOs, etc.

  Just curious either way.

  Thanks!

Cheers,
Duncan

Michael Hunger

unread,
Oct 1, 2012, 5:26:36 PM10/1/12
to ne...@googlegroups.com
Path is a Neo4j type.

It is usually represented as collection of nodes and relationships.

You can run any collection functions on it, like
- nodes(p)
- rels(p)
- extract
- length
- filter

etc.

HTH

Michael
> --
>
>

Duncan Brown

unread,
Oct 1, 2012, 5:32:22 PM10/1/12
to ne...@googlegroups.com
Great, was wondering if it was a type!

However, won't nodes(p) and rels(p) just return a single value each as well?  E.g. here: http://docs.neo4j.org/chunked/milestone/query-function.html

...trying it in the web console, though, I can see it returns a stream.  Interesting.

Will investigate deeper.

Thanks once again!

--



Michael Hunger

unread,
Oct 1, 2012, 5:42:13 PM10/1/12
to ne...@googlegroups.com
nodes(p) and rels(p) just return collections of nodes and relationships respectively

Michael

--
 
 

Duncan Brown

unread,
Oct 1, 2012, 5:48:09 PM10/1/12
to ne...@googlegroups.com
How will SDN interpret that?  Will it know to stick it into an Iterable (or something comparable)?  Or does it have to be parsed out?

--
 
 

Michael Hunger

unread,
Oct 1, 2012, 5:54:41 PM10/1/12
to ne...@googlegroups.com
There are several ways how SDN interacts with that.

You can convert it to a collection of nodes or entities or to a collection of paths. Just by declaring Collection<Node> or Collection<Person> as your method return type or
using template.query(...).to(Person.class)

Michael

There is also the concept of an EntityPath but that hasn't been used very much so far.

--
 
 

Duncan Brown

unread,
Oct 1, 2012, 5:58:02 PM10/1/12
to ne...@googlegroups.com
Thanks, Michael.  I'll give all of those a shot.  I'm actually eager to collect a lot of info about a given path, especially the traversal itself (i.e. which node goes to which relationship goes to which node, etc.).  Should be fun when I get a chance!

--
 
 

Michael Hunger

unread,
Oct 1, 2012, 6:02:46 PM10/1/12
to ne...@googlegroups.com
Cool,

keep us informed how it goes.

Michael

--
 
 

Michael Hunger

unread,
Oct 2, 2012, 3:12:10 AM10/2/12
to ne...@googlegroups.com
by using parameters,

> start n=node({id}) set n={props}


with {"id": 3, "props" : {"type":"Employee","name":"jane","famil":"stone"}}

Michael

Am 02.10.2012 um 08:55 schrieb hooman rouhani:

> hi i have one question.
> how can i edit node content not property by property?
> for example:
> here is my node : start n=node(3) return n; ---> n={type:"Person",name="john"}
> i want to do something like this:
> start n=node(3) set n={type:"Employee",name:"jane",famil:"stone"}
> Instead of this:
> start n=node(3) set n.type="Employee",n.name="jane",n.famil="stone"
>
> --
>
>

BtySgtMajor

unread,
Oct 5, 2012, 12:57:59 PM10/5/12
to ne...@googlegroups.com
So I thought I'd play around a bit both with the @Query, etc. annotations as well as the EntityPath bit.

I didn't get very far with EntityPath as, by the sounds of it. I either have to figure out how to specify a "shortest path" traversal, or how to otherwise get a Cypher query to map to an EntityPath.  I'm still digging with what little free time I have.

With the Collection<Node> suggestion above, I've noticed that, when returning a Path from Cypher, I only get the last node in the path.  If I return NODES(path), I get the starting node in the path.  I'm using Collection<Node> as the return type in the repository method as I have nodes of varying types in the path.

 I'll keep digging to see if I'm doing anything silly.

Michael Hunger

unread,
Oct 5, 2012, 11:49:56 PM10/5/12
to ne...@googlegroups.com
You should just be able to return an EntityPath in cypher itself you would return your 
match p=a--b return p

If you only return a single value (node or entity) it only returns a single element of the path, that's true.

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages