Graph Modeling boolean value - relationship property, or node property or none at all?

泪湿孤枕 提交于 2020-07-10 08:41:10

问题


Context

A business has many Partners. Each partner could offer multiple Services to their customers. Some Partners offer All Services, some offer a few. The business can always sell a Product to that Partner, and which Product can be sold depends on whether the Partner offers a particular Service or not. So business could sell Product A to Partner A offering Service A. They could offer Product B to Partner A if they don't offer Service B.

Question - if Partners, Products, Services are nodes, where should I model the question 'is this Service offered by this Partner?" Another business question would be "Whats my market for Product A?" - which should return all the Partners that don't offer the Service Built with Product A. Should I do:

  1. Partner_OFFERS_Service_BUILT_WITH_Product (only have Partner_Service relations where Offered=yes). In this case, how would i return the partners that could be sold a product for Service they don't yet offer?
  2. Partner_COULD-OFFER_Service_BUILT_WITH_Product,and have Offered=yes/no as a property on the COULD_OFFER relationship
  3. Partner_COULD-OFFER_Service_BUILT_WITH_Product, and have Offered=yes/no as a property on the node Service. EDIT:This wouldn't work as I can't have this property for every partner.
  4. Have 2 different kinds of relationships - OFFERS and DOESNT_OFFER to relate every partner to every service, but then have a mechanism to switch the relationship if adoption changes.

This will be the backend for a Spring Java application. I understand it could be done in multiple ways and trying to understand simplest way to do this from a query and coding perspective.

EDIT Having discussed with users, the requirement just got more complex. What they actually do is something like a table in relational world with following columns (its denormalised with lot of repetitive data:

PartnerName | Service | Offered? |CurrentlyUsing | WeCouldSellThese |

XX | Baking | Yes |Competitor A, B | Product A | XX | Baking | Yes |Competitor A, B | Product C | XX | Baking | Yes |Competitor A, B | Product D | XX | OnlyDough| Yes |Product A | Product C | XX | Packing | No | | Product E |

Basically, they need to store information what is being used currently, and whether its currently offered by partner or not, they still try to sell them products (Offered Yes or No will both still lead to a market). There is a many-to-many relationship between service and product as well...which means there is a "3node" relationship - A prospect is defined as a particular partner for a particular product for a particular service, I've tried the following model, but not sure how to query Could_Buy and To_Build together, when there would be multiple of these relationships on a single product.


回答1:


The most simplistic design that should work for you is creating following relationships:

  1. Node(Partner) - [OFFERS] -> Node(Service)

  2. Node(Service) - [BUILT_WITH] -> Node(Service)

    Example: PartnerA - OFFERS - ServiceA, ProductA - BUILT_WITH - ServiceA, ProductB - BUILT_WITH - ServiceB

Now how to answer your business questions:

  1. Is this Service offered by this Partner? : This is pretty straight forward. You just need to check if 'OFFERS' relationship exists between a Service and a Partner.
  2. What's my market for Product A?: You can fetch all Services 'BUILT_WITH' Product A. (which is ServiceA). Next, fetch all the Partner nodes for which 'OFFERS' relationship doesn't exist with ServiceA. Pretty sure, a single query can help achieve this result in Neo4j.


来源:https://stackoverflow.com/questions/61299233/graph-modeling-boolean-value-relationship-property-or-node-property-or-none-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!