简体   繁体   中英

Bidirectional Data modeling issue in neo4j

I have two nodes, A and B, A talks to B and B talks to A, (A)-[:talksTo]-(B)

A has a sentiment value towards B, and B has a sentiment value towards A.

So there is the problem, I need A to B relationship to store a value that the B to A relationship will also want to store (same key).

So I will try to do queries such as, MATCH (A:person)-[:talksTo]-(B:person) where A.sentiment < -2 return A;

So here A's sentiment toward B will be different the B's sentiment toward A, thus the needed separation.

I have tried to make unique key names to specify direction - but that makes queries difficult unless I can query with a wild card ex: ... where A.Asentiment < -2 would be queried as ... where A.*sentiment < -2

Another way I can think of to do this is make two different graphs, 1) A talks to B graph and B talks to A graph... but this would make queries tricky as I may get back more then one node for single node queries OR if I have to update a single node key:value to something else. I would prefer to have one node name per person.

Any ideas?

I don't know that this is a solution, but I don't think I understand enough so it might be a foil for better understanding:

MATCH (A:Person)-[dir1:talksTo]->(B:Person), (A)<-[dir2:talksTo]-(B)
WHERE dir1.sentiment < 2
RETURN A, B

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