3

In my flight modelization, I would like to search for path with 1 stop which is equivalent in the graph to have a 4 hops relationships from the source to the destination. When searching the path with :

     match (s:Airport{airportName:'CAN'}),
     (d:Airport{airportName:'ICN'})
     with s,d 
     match p = (s)<-[*4]->(d)
     return  nodes(p), relationships(p) 

But this also give me path with airport node that are visited twice, like this : airport node

So my question is, how to exclude paths which contains duplicated nodes ? How to detect whether there is a duplicated node within a path ?

Thank you !

Liam
  • 27,717
  • 28
  • 128
  • 190
filipyoo
  • 347
  • 1
  • 7
  • 15

1 Answers1

2

If you have access to APOC Procedures, you can try using apoc.algo.allSimplePaths(), which will not contain any loops back to a previously visited node in the path.

 match (s:Airport{airportName:'CAN'}),
  (d:Airport{airportName:'ICN'})
 call apoc.algo.allSimplePaths(s, d, '', 4) yield path
 return  nodes(path), relationships(path)
InverseFalcon
  • 29,576
  • 4
  • 38
  • 51