Cypher and shortestPath

Showing 1-12 of 12 messages
Cypher and shortestPath BtySgtMajor 10/1/12 9:26 AM
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
Re: [Neo4j] Cypher and shortestPath Michael Hunger 10/1/12 2:26 PM
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

Am 01.10.2012 um 18:26 schrieb BtySgtMajor:
> --
>  
>  

Re: [Neo4j] Cypher and shortestPath BtySgtMajor 10/1/12 2:32 PM
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!

--



Re: [Neo4j] Cypher and shortestPath Michael Hunger 10/1/12 2:42 PM
nodes(p) and rels(p) just return collections of nodes and relationships respectively

Michael

Am 01.10.2012 um 23:32 schrieb Duncan Brown:

--
 
 

Re: [Neo4j] Cypher and shortestPath BtySgtMajor 10/1/12 2:48 PM
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?

--
 
 

Re: [Neo4j] Cypher and shortestPath Michael Hunger 10/1/12 2:54 PM
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.

Am 01.10.2012 um 23:48 schrieb Duncan Brown:

--
 
 

Re: [Neo4j] Cypher and shortestPath BtySgtMajor 10/1/12 2:58 PM
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!

--
 
 

Re: [Neo4j] Cypher and shortestPath Michael Hunger 10/1/12 3:02 PM
Cool,

keep us informed how it goes.

Michael

Am 01.10.2012 um 23:58 schrieb Duncan Brown:

--
 
 

Re: Cypher and shortestPath hooman rouhani 10/1/12 11:55 PM
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"
Re: [Neo4j] Re: Cypher and shortestPath Michael Hunger 10/2/12 12:12 AM
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:
> --
>  
>  

Re: [Neo4j] Cypher and shortestPath BtySgtMajor 10/5/12 9:57 AM
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.
Re: [Neo4j] Cypher and shortestPath Michael Hunger 10/5/12 8:50 PM
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

Am 05.10.2012 um 18:57 schrieb BtySgtMajor:

--