I have a schema, where nodes are connected by 2 types of relationship - r:A and r:B. I'm trying to write a pattern, which will find every path from node N to node M. This can be simply done by following cypher query:
match path = (n)-[:A|:B*]->(m) return path;
Unfortunately this is not what I need exactly. I need to find every path from (n) to (m) where depth via relation r:A can be infinite, but along the way only limited number of r:B relations can be use. In happy day scenario the cypher query would look like this:
match path = (n)-[:A*|:B*0..3]->(m) return path;
However cypher does not allow this syntax. I can't solve this problem even with usage of another "helping" node on the way:
match path = (n)-[:A*]->()-[:B*0..3]->(m) return path;
This does not match my need also, because the nodes can be interconnected in any possible way. For example:
(n)-[r:A]-()-[r:A]-()-[r:A]-(m)
(n)-[r:A]-(m)
(n)-[r:A]-()-[r:B]-()-[r:A]-()-[r:B]-()-[r:A]-()-[r:A]-(m)
Is there a way how this can be achieved? If not in cypher, can it be done in gremlin / neo4j traversal api / embedded functions of spring data neo4j project?
Thank's for the answers.