先做一個簡單的資料
CREATE (ACME:DeptGroup:OrgGroup {id: 'Ga', name: 'ACME'}) CREATE (ACME_Member:UserGroup {id: 'Gb', name: 'allmember'}) CREATE (Keanu:Person {id: 'Ua', name: 'Keanu Reeves'}) CREATE (Dev1:DeptGroup:OrgGroup {id: 'Gc', name: 'Development 1'}) CREATE (Dev1_Mmember:UserGroup {id: 'Ge', name: 'allmember'}) CREATE (Project_Lineage:ProjectGroup:OrgGroup {id:'Gg', name: 'Project Lineage'}) CREATE (Lineage_Mmember:UserGroup {id: 'Gj', name: 'allmember'}) CREATE (Unity_ResearchGroup:ProjectGroup:OrgGroup {id:'Gh', name: 'Unity Research Group'}) CREATE (Unity_Mmember:UserGroup {id: 'Gk', name: 'allmember'}) CREATE (Dev2:DeptGroup:OrgGroup {id: 'Gd', name: 'Development 2'}) CREATE (Dev2_Mmember:UserGroup {id: 'Gl', name: 'allmember'}) CREATE (Project_X:ProjectGroup:OrgGroup {id: 'Gi', name: 'Social Game Project X'}) CREATE (X_Mmember:UserGroup {id: 'Gm', name: 'allmember'}) CREATE (Dev1)-[:SUPERVISED_BY]->(ACME), (Dev2)-[:SUPERVISED_BY]->(ACME), (Project_Lineage)-[:SUPERVISED_BY]->(Dev1), (Unity_ResearchGroup)-[:SUPERVISED_BY]->(Dev1), (Project_X)-[:SUPERVISED_BY]->(Dev2), (ACME_Member)-[:BELONG_TO]->(ACME), (Dev1_Member)-[:BELONG_TO]->(Dev1), (Dev2_Member)-[:BELONG_TO]->(Dev2), (Lineage_Mmember)-[:BELONE_TO]->(Project_Lineage), (Unity_Mmember)-[:BELONE_TO]->(Unity_ResearchGroup), (X_Mmember)-[:BELONE_TO]->(Project_X), (Dev1_Mmember)-[:SHARE_TO]->(ACME_Member), (Dev2_Mmember)-[:SHARE_TO]->(ACME_Member), (Lineage_Mmember)-[:SHARE_TO]->(Dev1_Mmember), (Unity_Mmember)-[:SHARE_TO]->(Dev1_Mmember), (X_Mmember)-[:SHARE_TO]->(Dev2_Mmember), (Lineage_Mmember)-[:SHARE_TO]->(Dev1_Mmember), (Unity_Mmember)-[:SHARE_TO]->(Dev1_Mmember), (X_Mmember)-[:SHARE_TO]->(Dev2_Mmember), (Keanu)-[:MEMBER_OF]->(ACME_Member)目的透過成員查詢到所屬UserGroup的同時,把有設定[:SHARE_TO]的relation的多層關係的UserGroups都查詢出來。
match (p:Person {id:'Ua'})-[:MEMBER_OF]->(u:UserGroup) return u.id as gid union match (udeep:UserGroup)-[:SHARE_TO*]->(u) return udeep.id as gid之前是自己實作adjacency list解決速度的問題,看來也可以輕鬆地改用Neo4j搞定。
沒有留言:
張貼留言