图表数据库中的推荐建模

时间:2016-02-13 16:42:49

标签: neo4j graph-databases

我是图形数据库领域的新手,并且对以下产品买卖双方关系的经典场景推荐的建模选项感到疑惑:

  • 史蒂夫从亚马逊购买了iPhone 6 Plus

    创建(史蒂夫:人{姓名:"史蒂夫"}) - [b1:BOUGHT] - >(iPhone:产品{名称:" iPhone 6 Plus"})< ; - [s1:卖出] - (亚马逊:公司{名称:"亚马逊"})

  • Michael然后还买了iPhone 6 Plus,但是来自eBay

    创建(迈克尔:人{姓名:"迈克尔"}) - [b2:BOUGHT] - >(iPhone)< - [s2:卖出] - (eBay:公司{名称:& #34;易趣"})


因此,亚马逊和eBay都出售iPhone 6 Plus,史蒂夫和迈克尔都买了它。
CLICK TO VIEW ILLUSTRATED MODEL WITH THE PRODUCT NODE
问题: 这种合并模型存在一个问题,因为从节点" iPhone 6 Plus"以及史蒂夫或迈克尔购买iPhone 6 Plus的公司不清楚。共享

建模可以简化为:

CREATE (Steve:Person {name: "Steve"})-[b1:BOUGHT_FROM {product: "iPhone 6 Plus"}]->(Amazon:Company {name: "Amazon"})
CREATE (Michael:Person {name: "Michael"})-[b2:BOUGHT_FROM {product: "iPhone 6 Plus"}]->(eBay:Company {name: "eBay"})


CLICK TO VIEW ILLUSTRATED MODEL WITHOUT THE PRODUCT NODE
导致失去了iPhone 6 Plus"节点并将其替换为关系属性本身嵌入细节的方法,但允许Steve和亚马逊之间存在直接关系。

有没有办法在史蒂夫从亚马逊购买iPhone时保持清晰的信息,迈克尔也从eBay购买了iPhone并同时保留了iPhone的节点?

1 个答案:

答案 0 :(得分:0)

作为一个简单的选项,您可以添加与销售Purchase相关的Company节点以及从该公司购买的一个或多个Products

以下说明了数据模型,而不是任何Cypher条款。

  • 史蒂夫从亚马逊购买了iPhone 6 Plus

    (:Person {name: "Steve"})-[:BOUGHT]->(p:Purchase {id:987, total: 655.99, tax: 56.00})
    (p)-[:PRODUCT {price: 599.99}]->(iPhone:Product {name: "iPhone 6 Plus"})
    (p)-[:SELLER]->(:Company {name: "Amazon"})
    
  • Michael然后还买了iPhone 6 Plus,但是来自eBay

    (:Person {name: "Michael"})-[:BOUGHT]->(p:Purchase {id:456, total: 599.99, tax: 0.00}})
    (p)-[:PRODUCT {price: 599.99}]->(iPhone:Product {name: "iPhone 6 Plus"})
    (p)-[:SELLER]->(:Company {name: "eBay"})
    

Steve购买的实际查询可能如下所示:

MERGE (person:Person {name: "Steve"})
MERGE (prod:Product {name: "iPhone 6 Plus"})
MERGE (co:Company {name: "Amazon"})
CREATE
  (person)-[:BOUGHT]->(p:Purchase {id:987, total: 655.99, tax: 56.00}),
  (p)-[:PRODUCT {price: 599.99}]->(prod),
  (p)-[:SELLER]->(co);