Is there a way to do variable-length pattern matching queries in dgraph?
Some examples (note that an asterisk (*) below denotes any number of hops along a path):
1. Find paths between node (A or B) and (C or D) but must include E
match p = (a)-[*]->(b) WHERE (a.name = 'A' OR a.name = 'B') AND
(b.name = 'C' OR b.name = 'D') AND any(x IN nodes(p) WHERE x.name='E') return p
2. Find paths between node (A or B) and (C or D) but must not include E
match p = (a)-[*]->(b) WHERE (a.name = 'A' OR a.name = 'B') AND
(b.name = 'C' OR b.name = 'D') AND all(x IN nodes(p) WHERE NOT x.name='E') return p
3. Find a random path between node (A or B) and (C or D)
match p = (a)-[*]->(b) WHERE (a.name = 'A' OR a.name = 'B') AND
(b.name = 'C' OR b.name = 'D') with collect(p) as allP, length(collect(p)) as totalP
return allP[toInteger(rand()*(totalP-1))]
4. Find paths that match a more complex pattern:
A - * - B - * - C - * - D - * -> E