简体   繁体   中英

Zero or more length of path in Cypher

For example I have a path:

1-[:A]->2-[:B]->3

And we can use the * operator to define if a particular edge can be repeated. I would like to use the * operator on the entire path, or both edges combined. I would like to follow: (A AND B) zero or more times.

Example:

1-[:A]->2-[:B]->3-[:A]->4-[:B]->5...

I am not sure how to apply the * operator for the entire path in Cypher. My intent is to express a pattern that allows a specific path to be repeated 0 or more times.

This is something variable-length patterns cannot do in Cypher. However, because of this, we added repeating sequences functionality to path expander procs in APOC Procedures .

As an example:

MATCH (n)
WHERE id(n) = 123
CALL apoc.path.expandConfig(n, {relationshipFilter:'A>, B>'}) YIELD path
RETURN path

This expands from a start node ( n ) expanding out only a repeating sequence of outgoing :A and :B relationships. No minLevel or maxLevel properties were provided, so this has a minimum of 0 length and no bounds on max length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM