0
votes

I got a graph with circular type relationship. So there may have two different direction relationships (outgoing and incoming) between each node in my graph. I am trying to find the path between two nodes without using shortestpath(). How to give the condition to set only 1 relationship will show between each node in the path? Here is my query:

Match p = (A)-[r*]-(b) return p

What should I write for where part?

1
First, if you don't use shortestpath(), you need to cap your [r*] so that the query doesn't pull up infinite paths. Also are you trying to find all paths that uses each edge only once?Tezra
I am trying to find the shortest distance between two nodes. I have distance property in my relationships type GO_TO. I think it should be only once but not all edges. For example, I have two nodes A,B and I also have two relationships GO_TO between A,B(incoming and outgoing) I only want outgoing direction show in my path. So when I query the path between A-F. It should only show A->B->C->D->E->F @TezraLin Bernie

1 Answers

0
votes

So what yo really want is shortest weighted path. Cypher doesn't directly support this yet, but you can query it like this

MATCH (start:Point {id: '1'}), (end:Point {id: '2'})
MATCH p=(start)-[:GO_TO*1..25]->(end)
WITH p,reduce(s = 0, r IN rels(p) | s + r.myValueProp) AS dist
RETURN p, dist ORDER BY dist DESC LIMIT 1