'APOC/Neo4j: match variable length of relationships in between

For example, if I want to match a pattern like this:

MATCH (:Person)-[:A]->(:Movie)-[:B*]->(:Movie)-[:C]->(:Person)

where the first and last relationship's length ([:A] and [:C]) is fixed (they are both with length 1), but the middle relationship's length ([:B]) is variable.

Then the following paths will both match this pattern:

(:Person)-[:A]->(:Movie)-[:B]->(:Movie)-[:C]->(:Person)

(:Person)-[:A]->(:Movie)-[:B]->()-[:B]->(:Movie)-[:C]->(:Person)

I'm wondering if it's possible to use only one APOC path expander procedure (say apoc.path.expandConfig) and use the sequence to achieve this? (It seems that APOC does not support variable length of relationships in between though)

I know that I could create a new relationship between these two (:Movie) nodes based on this post but my goal is to return the whole path all at once, including the relationship and nodes between these two (:Movie) nodes.

Edited: This Cypher query can output what I want, but I want to compare the performance between Cypher and APOC (for research purposes). That's why I'm asking the equivalent way of using APOC for this query.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source