I have a graph where users can create cards represented by (:User)-[:created]->(:Card), and users can collected other user's cards which results in a clone of the original card: (:User)-[:collected]->(clone:Card)-[:describes]->(original:Card). Users can collect 'collected' cards, so we can end up with a tree of cards with the original created card at the root.
My problem is that in the original (Postgres) DB, some of the original cards have been deleted, so we don't have the canonical card. We're planning to find the 'orphaned' sub trees, find the new root of each sub tree and turn it into a 'created' card rather than a collected card. I think I'm homing in on a query that will give me all the candidate 'new' canonical cards, but I'm not sure if I'm getting the right results. I'd appreciate help from anyone who can spare the time to have a look at my query and tell me if you think it's giving me what I think it is... My logic in this query is: 1. match p = (c:Card)-[r:describes*]-(c1:Card) : this should match a complete tree by traversing all the [:describes] relations. The intention is that this should take any node in a tree of cards and match the whole tree (hence the non-directional relationship in the query) 2. where not any (x in nodes(p) where (x)<-[:created]-(:User)) : match the path when there isn't any node in the tree that has a [:created] relation 3. return distinct filter (card in nodes(p) where not (card)-[:describes]->(:Card)) : give me the card in the path that doesn't have any outbound [:describes] relations which should be the root of the tree *Question 1: Is this giving me what I'm after?* match p = (c:Card)-[r:describes*]-(c1:Card) where not any(x in nodes(p) where (x)<-[:created]-(:User)) return distinct filter (card in nodes(p) where not (card)-[:describes]->(:Card)) I'm fairly sure this is giving me all the candidate new canonical cards. *Question 2: If so, how do I re-shape the query to allow me to change the relationships for these cards (change the [:collected] relation into a [:created] relation)?* Sorry for the long-winded post. I hope someone can point me in the right direction... :-) Thanks! Pete -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
