cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Shortest path

skirwan
Node Link

Hi all,

I am looking to get a Shortest path query that will get from one node label (:Person) to an company (:Organisation), this has to happen via multiple relationship types e.g (:Person)-[:Knows]-(:Person)-[:Colleague]-(:Person)-[:Works_For]-(:Organisation).

The dilema I face is that the [c:Colleague] relationship has properties such as c.Strength, where strenght can be weak, casual or strong. I would like my query to take this into account and only display the [c:Colleague] relationship that has the strong strength property. Also as a bonus id like the query to take in more relationship types such as [f:Friends] (Note:friends has the same strenght property).

Many thanks,
Sam.

4 REPLIES 4

ameyasoft
Graph Maven

Add the selected property value to the relationship:

(:Person)-[:Knows]-(:Person)-[:Colleague {Strength: "strong"}]-(:Person)-[:Works_For]-(:Organisation)

skirwan
Node Link

Hi,

Can you help me with the cypher for that,

I have tried the following but i get an error saying that you can only have one relationship type.

MATCH (c:Company{Name:"Aviation International"}),(p:Person{Name:"Sean Callaghan"}), (cc:Company),
p= shortestPath ((p)-[*]-(c)-[:Works_For{Strenght:"Strong"}]-(cc))
return p

Kind regards,
Sam.

Yeah @skirwan
First of all there is a tiny mistake in your query, you have used variable p multiple times .
Second yes you can do this. in shortest path you are giving multiple relationships. so do one thing just mentioned source node and terminal node that is Person and Company. and before that you just give a match that will have (c)-[:Works_For{Strenght:"Strong"}]-(cc)
hope so it works for you

skirwan
Node Link

Thanks for the reply, I think I have it resolved.

Kind Regards,
Sam.