简体   繁体   中英

Can graph database query “nodes that a given node has no relationship with”?

I am working on a dating app where users can "like" or "dislike" other users and get matched. As you can imagine the most important query of the app would be: Give me a stack of nearby user profiles that I have NOT liked/disliked before .

I tried to work on this with a document database (Firestore) and figured it's simply not suitable for such kind of application and hence landed in the graph database world which is new and fascinating to me.

I understand that by nature a graph database retrieves data by tracing through the relationships and make relationships first-class citizens. My question now is that what if the nodes that I am trying to get are those with no relationship from the given node ? What would the query look like? Can anyone provide an example query?

Edit: - added nearby criteria to the query statement

This is definitely possible, here is a query example :

MATCH (me:Profile {name: "Chris"})
MATCH (other:Profile) WHERE NOT (other)-[:LIKES]->(me)

As stated in the comments of your original question, on a large dataset it might not scale well, that said it is pretty uncommon that you would use only one criteria for matching, for example, the list of possible profiles to match from can be grouped by :

  • geolocation
  • profiles in depth 2 ( who is liking me, then find who other people they like, do those people like me ? )
  • shared interests
  • age group
  • skin color
  • ...

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