Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-14-2021 11:21 PM
Hi! I want to find all closed circles in a directed connection diagram. That is, a node has a path back to itself through any node. Thank you very much!
08-15-2021 10:36 PM
Hi,
You may try using the following code snippet to find the loops in the path.
MATCH p=((n)-[*..10]-(m)) WHERE ID(n)=Id(m) RETURN p
This code uses ID to find the same starting and ending node upto 10 hops. The maximum number of hops can be defined using param tag if required.
Best
Ishwarya
08-15-2021 11:40 PM
Thank you very much!
08-16-2021 04:07 AM
Hi @ruanlovelin !
This is probably one of the most expected functionalities on APOC. You should also consider cycles that are not closing on your starting node tho. I'm sending you an example of a working cypher on a small dummy db.
MATCH (p:NODE {ID: 4})
CALL apoc.path.expandConfig(p, {
relationshipFilter: "CON>",
minLevel: 1
})
YIELD path
with relationships(path) as rel, path
UNWIND rel as r
WITH path, rel, endNode(r) as node, count(endNode(r)) as c
where c> 1
RETURN path
UNION
MATCH (p:NODE {ID: 4})
CALL apoc.path.expandConfig(p, {
relationshipFilter: "CON>",
minLevel: 1,
terminatorNodes: [p]
})
YIELD path
RETURN path
H
08-17-2021 02:38 AM
I haven't understood it in a short time. I'll ask you if I have any questions .Thank you very much!
08-17-2021 03:03 AM
Hi!
First part of the union should calculate cycles that doesn't close on initial node. Second part does it.
H
08-18-2021 07:43 PM
Thank you for your reply, I really appreciate it. I want to query whether a node is in a closed circle,Or query all such circles. Could you tell me the second part solve it or not?
08-19-2021 02:44 AM
Hi,
Second part will give you cycles that start and close on the node p you define.
H
08-19-2021 05:21 PM
Thank you very much!
All the sessions of the conference are now available online