Neo4j 家谱关系设计

标签 neo4j relationship family-tree

我正在使用 Neo4j 设计大家族树。 在设计关系的过程中,我想到了两种方法:

  1. CREATE (p:Person)-[:PARENT_OF]->(s:Person) 创建(p:人)-[:STEPPARENT_OF]->(s:人) 创建 (p:Person)-[:MARRIED_TO]->(s:Person)

通过这种方法,我为每个案例创建了不同的关系(请记住,会有很多案例 = 很多关系)

  1. CREATE (p:Person)-[r:PARENT_OF {type:'natural'}]->(s:Person) 创建 (p:Person)-[r:PARENT_OF {type:'step'}]->(s:Person) 创建 (p:Person)-[r:SPOUSE_OF {type:'marriage'}]->(s:Person)

使用这种方法,关系会减少,但设计会有点困惑。

我想知道哪种方法更好,为什么?

最佳答案

您正在选择细粒度(:PARENT_OF:STEPPARENT_OF:MARRIED_TO)或通用关系(:PARENT_OF {type:'natural'}, :PARENT_OF {type:'step'}, :SPOUSE_OF {type:'marriage'}).

Ian Robinson、Jim Webber 和 Emil Eifrém 所著的图形数据库一书(可在 Neo4j 网站上以 download 的价格获得)说:

Differentiating by relationship name is the best way of eliminating large swathes of the graph from a traversal. Using one or more property values to decide whether or not to follow a relationship incurs extra I/O the first time those properties are accessed because the properties reside in a separate store file from the relationships (after that, however, they’re cached).

请记住,应根据应用程序需求构建图数据库模型。也就是说:这基本上取决于您向数据库提出的查询类型。

  • 如果您需要评估图横向查询中关系的类型,将其拆分为单独的关系类型可能是个好主意。
  • 否则,将其保留为通用关系类型的属性。

关于Neo4j 家谱关系设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44386230/

相关文章:

sql-server - 使用 ASP.NET MVC 和 SQL Server 实现家谱的最佳方法是什么

ruby-on-rails - 使用 Neo4j 的 Carrierwave 未将图像关联保存到数据库

python - 使用多个属性键进行 Py2Neo 合并

php - 获取 'pivot'表中的所有字段

.net - 图和关系数据库

c++ - 为什么将我的打印方法与 std::cout 一起使用会导致错误?

java - 如何使用 Spring Data 实现只读属性?

macos - Neo4j 配置文件

python - 在 sqlalchemy 中绑定(bind)关系时分配变量

swift - 如何与核心数据建立多对多关系? swift ,xcode