Closed kowaalczyk closed 4 years ago
You're getting a different result because of your CREATE
statements for the relationships - it looks like, instead of running the query as a block of code, you're running each line individually. When you use CREATE (nAlice:User {name: 'Alice'})
you temporarily create a variable (nAlice) that refers to the node with the name of Alice, however, the variable doesn't persist between queries -- so it's not available when you run CREATE (nAlice)-[:LINK {weight: 0.5}]->(nBridget)
.
So if you run:
CREATE (nAlice:User {name: 'Alice'})
CREATE (nBridget:User {name: 'Bridget'})
CREATE (nCharles:User {name: 'Charles'})
CREATE (nDoug:User {name: 'Doug'})
CREATE (nMark:User {name: 'Mark'})
CREATE (nMichael:User {name: 'Michael'})
CREATE (nAlice)-[:LINK {weight: 0.5}]->(nBridget)
CREATE (nAlice)-[:LINK {weight: 4}]->(nCharles)
CREATE (nMark)-[:LINK {weight: 1.1}]->(nDoug)
CREATE (nMark)-[:LINK {weight: 2}]->(nMichael);
As a single Cypher statement, then call the algo, you should get the results you expect :)
I tried to use the unionFind algorithm, but I was unable to get the correct results: it assigned every node to its own component, without merging the connected nodes.
After more investigation I couldn't even reproduce the example from official documentation:
The expected result would be 2 connected components (partitions), but as you can see I got 6.
My setup is:
I'm not sure what the issue is, there is a chance I may have done something wrong - I started using neo4j only yesterday so I'm not really familiar with the project, and I'll greatly appreciate some help :)