neo4j conditional relationship

試著忘記壹切 提交于 2019-12-13 16:34:42

问题


I am currently working on a program using graph db - neo4j and I need to realize the following function.

  1. I have two types of nodes, type A means stage, type N means let the user do some selections.
  2. First we have node A1, which has several (2-5) type N children, N1, N2, N3, ...
  3. Nodes A1 also have child nodes A2, A3, ...
  4. In java, after arriving at A1, I will ask the users to do some selections according to Ni, then go to a type A child based on a function of the selections. For example, if N1=true, N2=true, N3=false, I go to A2, otherwise, I goto A3.

BTW, I will meet this situation many many times in my program. Do you guys have any idea how to implement it efficiently.

Thanks in advance.


回答1:


Suggestion for Setup

(Ax)-[:TRUE ]->(Nx)-[:TRUE ]->(Ax+1)
(Ax)-[:FALSE]->(Nx)-[:FALSE]->(Ax+1)

Suggestion for Query

 MATCH (a:A {id:1}),
       (a)-[:TRUE]-> (n)-[:FALSE]->(a2),
       (a)-[:FALSE]->(n2)-[:TRUE]->(a2),
       (a)-[:TRUE]-> (n)-[:FALSE]->(a2)
 RETURN a2;



回答2:


Thanks to @Michael Hunger, I think I find an acceptable solution, although it seems a lot of work to do.

Specifically, I expand all the pathes from A1 through Ni and link the only path when all Ni=true to A2* and all the other paths to A3 as the following graph:



来源:https://stackoverflow.com/questions/35694532/neo4j-conditional-relationship

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