title: Cypher query to check node connectivity
body: <p>I'm new to neo4j and would really appreciate your help for this.</p>
  
  <p>I have following graph created in neo4j.</p>
  
  <p>n1----n2----n3----n4---n5</p>
  
  <p>n1,n2,n3,n4,n5 all are nodes
  --- : relationship_type_1 (REL)</p>
  
  <p>Now given any set of nodes (in any order), I want to check whether these nodes are connected or not.
  E.g. Given n1, n2, n3          ==> Connected.
       Given n1, n3, n2, n4, n5  ==> Connected.</p>
  
  <p>How should I formulate my cypher query to check connectivity?</p>
  
  <p>Following query is working even if I change the order,</p>
  
  <pre><code>MATCH p=_1--_2--_3 
  WHERE _1.name?="Node1" and ALL (n in nodes(p) 
    WHERE n.name IN ["Node1", "Node2", "Node4"]) 
  RETURN nodes(p);
  </code></pre>
  
  <p>on <a href="http://console.neo4j.org/?id=xl8pnl" rel="nofollow">http://console.neo4j.org/?id=xl8pnl</a></p>
  
  <p>but if I provide start nodes instead of using _1,_2 and change the order then it's not returning me the path. :(</p>
  
  <p><a href="http://console.neo4j.org/?id=xl8pnl" rel="nofollow">http://console.neo4j.org/?id=xl8pnl</a>
  for following query,</p>
  
  <pre><code>START p1=node(6),p2=node(5),p3=node(4) MATCH p=p1--p2--p3 
  WHERE p1.name?="Node1" AND ALL (n IN nodes(p) WHERE n.name IN ['Node1' ,'Node3', 'Node2' , 'Node4']) 
  RETURN nodes(p)
  </code></pre>
  
  <p>it doesn't return the path as nodes are connected in node(6)-node(5)-node(4) order.</p>