简体   繁体   中英

How do I model social network connections in neo4j?

Thinking about how to model a simple graph for a Side project.

The project's users will be able to add social networks so that they can find other users with social information.

Given neo4j's architecture, which I'm new to, is the correct way to do this:

  1. A different type for each social network (eg, twitter, LinkedIn) and a relationship of user --> has_twitter_account / user --> has_linkedin_account with relevant keys
  2. one type (SocialMediaAccount) with user --> has_socialmedia_acct relationship with relevant keys In a more generic way and an attribute for name of social network
  3. adding social networks as attributes under each User entity?
  4. Something else I haven't thought of?

I'm leaning towards number 1 but given that I'm a newcomer I want to make sure this isn't an anti-pattern or setting me up for pain later.

Not sure if I understand you requirements correctly, but in general, it's good to model real world entities as nodes and relationships between things, quite naturally, as relationships.

In your case, I'd go one of the two following ways, depending on how much you want to do with their social media accounts.

1) A node for each social media, eg (LinkedIn), (Twitter), (Facebook). Then a single relationship type, call it HAS_ACCOUNT, which links (user) nodes to accounts. For example:

(user1)-[:HAS_ACCOUNT]->(LinkedIn)

2) If you find you're storing too many properties in the HAS_ACCOUNT relationship, or even that you feel like it should be linked to something else (eg links between social media accounts), create a node for each account the user has.

(user1)-[:HAS_ACCOUNT]->(user1LinkedInAccount)-[:IS_ACCOUNT]->(LinkedIn)

That way, your model is more flexible and you can link users account together with a different kind of relationship. Say user1 follows user2 on Twitter:

(user1TwitterAccount)-[:IS_LINKED_TO]->(user2TwitterAccount)

Hope it makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM