0
votes

How to Ignore the match patterns which has occurrence of same node more than once while query shortest path, example case in portrait in attached image. enter image description here

Shortest path of A TO C gives,

start a=node:node_auto_index(point='A'),c=node:node_auto_index(point='c') match p=a-[r:CONNECTS*]->c return p;

1. A-> C
2. A -> B -> C -> A -> C
3. A -> B -> C
4. A -> C -> A -> C
5. A -> B -> A -> C
6. A -> C -> B -> A -> B -> C

and more of 9 pattern, but in some pattern same node or start and end node are appeared more than once which will be like irrelevant output, so how can i identify and ignore the pattern which has any node's more than once in its path.

2
Which version of Neo4j are you using?jjaderberg
@jjaderberg version 1.9.5Jeevanantham

2 Answers

1
votes

You didn't use shortest path. The correct query is:

start a=node:node_auto_index(point='A'),
      c=node:node_auto_index(point='c') 
match p=shortestPath((a)-[r:CONNECTS*]->(c)) 
return p;

Or allShortestPaths

0
votes

found Solution for the above case

START a=node:node_auto_index(point='a'),
c=node:node_auto_index(point='c')
MATCH path= a-[r:CONNECTS*]->c
WHERE ALL(n in nodes(path) where 1=length(filter(m in nodes(path) : m=n))) 
RETURN path; 

Now its resulting only the valid paths as expected :-)

1. A -> B -> C
2. A -> C