If the number of properties is greater than n, return from a highly connected graph in Neo4j

后端 未结 1 742
耶瑟儿~
耶瑟儿~ 2021-01-27 11:24

This question is a direct extension of a question I asked previously here (and and even earlier version here).

Say I have a graph database that looks like this:

相关标签:
1条回答
  • 2021-01-27 11:56

    If this is about families of people, then easiest fix is to add a :Family node for each relational group, like so:

    create (f:Family) with f 
    match (a:person {name:"Adrian"})-[:RELATED_TO*]->(b:person)  
    merge (f:Family)<-[:FAMILY]-(a) 
    merge (f:Family)<-[:FAMILY]-(b)
    

    Replace "Adrian" with "Barry" to create the second family group.

    That gives you a central :Family node for each family group. You can then pick the family group that has enough :person.SomeProperty = "Yes" family members like so:

    // Find families with 2 or more :person.SomeProperty = "yes"
    match p = (f:Family)<-[:FAMILY]-(psn:person)
    where psn.SomeProperty = "Yes"
    with  f, count(psn) as cnt 
    where cnt > 2
    
    // Get the family members 
    match (a:person)<-[r1:RELATED_TO]-(b:person)-[r2:RELATED_TO*]->(c)
    where (a)-[:FAMILY]-(f)
      and a = c  // to get all the nodes in the loop 
    
    // report the first record which'll have two  
    // family members and all the relationships
    return a, r1, b, r2 
    limit 1
    
    0 讨论(0)
提交回复
热议问题