I'm new to neo4j and would really appreciate your help for this.
I have following graph created in neo4j.
n1----n2----n3----n4---n5
n1,n2,n3,n4,n5 all are nodes --- : relationship_type_1 (REL)
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.
How should I formulate my cypher query to check connectivity?
Following query is working even if I change the order,
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);
on http://console.neo4j.org/?id=xl8pnl
but if I provide start nodes instead of using _1,_2 and change the order then it's not returning me the path. :(
http://console.neo4j.org/?id=xl8pnl for following query,
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)
it doesn't return the path as nodes are connected in node(6)-node(5)-node(4) order.