Vote count:
0
Any help would be much appreciated.
I am experimenting with Neo4j and am trying to assign a unique (arbitrary) ID to individual isolated networks.
For instance, as in the picture below, I would like to find items connected to the box type they were shipped in. Then assign a group ID for all connected items.
(i:Item)-[:SHIPPED_IN]->(b:Box)
Queries like this get me close but I still end up with connected nodes having different GroupIDs. At this point, especially with the second query, I'm pretty sure I'm over complicating things.
MATCH (i:Item)-[:SHIPPED_IN]->(b:Box)<-[:SHIPPED_IN]-(ii:Item) with distinct i, collect(ii) as icol FOREACH (n IN icol | SET n.GroupID = id(i), i.GroupID = id(i) )
...or...
MATCH (i:Item)-[:SHIPPED_IN]->(b:Box)<-[:SHIPPED_IN]-(ii:Item) where i <> ii with i, collect(ii) as icol FOREACH (n IN icol | SET i.GroupID = COALESCE(i.GroupID, id(i)), n.GroupID = COALESCE(n.GroupID, i.GroupID))
Is there an easy, efficient way to accomplish this? Thanks in advance!
Identify Isolated Networks with Neo4J
Aucun commentaire:
Enregistrer un commentaire