thanks for your reply
i am working on some patterns, some of them are as simple as linear pattern such as
- (A)-[R]->(B)-[R]->(C)
some of them are a little more complicated
- (A)-[R]->(B)-[R]->(C)
-
(B)-[R]->(D)
in these cases one or more Branch Point exist in patterns. Nodes like B are Branch Point. which means in this point pattern forked into more than one line of pattern.
(B) = branch point
1- (B)-[R]->(C)
2- (B)-[R]->(D)
...
these (BP)s may be chained together. Some of these (BP)s have special conditions, and some haven't.
for example
1- B must be related to C by R
and
2- B must be related to D by R
-
as in Neo4j Cypher documents explained, these conditions must be written with WHERE clause after respective MATCH clause. so we have
-
MATCH ((a:A)-[:R]->(b:B)),
-
((b)-[:R]->(:C)),
-
((b)-[:R]->(:D))
return a,b
- if operator of this (BP) changes to OR as [jaini.kiran] explained the cypher changes as follows
MATCH (a:A)-[:R]->(b:B)
where (b)-[:R]->(:C) OR (b)-[:R]->(:D)
return a,b
or as you explained this case can be implemented with UNION clause
cypher statement changes to :
MATCH (a:A)-[R]->(b:B)
WHERE exists((b)-[:R]->(:C) **1) or exists((b)-[:R]->(:D) **2)
RETURN a,b
Suppose all (BP)s have OR operator between outgoing relationships.
Question : in **1 and **2 how can i write the continuation of the cypher.
i counted on the (BP)s and their leaves.
(BP)s B,C and D
Leaves M,N,P and Q
based on leaves for each BP create a list of valid (BP)s. from last to first
** C Break Point
1-MATCH (A)-[R]->(B)-[R]->(C)-[R]->(M)
with collect(C) as c_list1
2-MATCH (A)-[R]->(B)-[R]->(C)-[R]->(N)
with c_list1, collect(C) as c_list2
3-MATCH (A)-[R]->(B)-[R]->(c:C)
where any(item in c_list1 where item=c) or any(item in c_list2 where item=c)
with collect(c) as c_list
** D Break Point
4-MATCH (A)-[R]->(B)-[R]->(D)-[R]->(P)
with c_list, collect(D) as d_list1
5-MATCH (A)-[R]->(B)-[R]->(D)-[R]->(Q)
with c_list, collect(D) as d_list2
6-MATCH (A)-[R]->(B)-[R]->(d:D)
where any(item in d_list1 where item=d) or any(item in d_list2 where item=d)
with c_list, collect(d) as d_list
** B Break Point
7-MATCH (A)-[R]-(B)-[R]-(c:C)
where any( item in c_list where item=c)
with d_list, collect(B) as b_list1
8-MATCH (A)-[R]-(B)-[R]-(d:D)
where any( item in d_list where item=d)
with b_list1, collect(B) as b_list2
** Create Result
9-MATCH (a:A)-[R]->(b:B)
where any(item in b_list1 where item=b) or any(item in b_list2 where item=b)
return a,b
? is this the right solution
thanks a lot