美文网首页
Neo4j Cyber 使用

Neo4j Cyber 使用

作者: shpunishment | 来源:发表于2019-06-06 19:01 被阅读0次

    只有单向关系
    CREATE 语句:
    创建节点和单双向关系

    1 -> 2 -> 5 -> 9
             -> 6
       -> 3 -> 7 -> 10
       -> 4 -> 8   
    create (zhang1:People{name:'zhang1'}) 
    create (zhang2:People{name:'zhang2'}) 
    create (zhang3:People{name:'zhang3'})
    create (zhang4:People{name:'zhang4'})
    create (zhang5:People{name:'zhang5'})
    create (zhang6:People{name:'zhang6'})
    create (zhang7:People{name:'zhang7'})
    create (zhang8:People{name:'zhang8'})
    create (zhang9:People{name:'zhang9'})
    create (zhang10:People{name:'zhang10'})
    
    create (zhang1)-[:FOLLOW]->(zhang2)
    create (zhang1)-[:FOLLOW]->(zhang3)
    create (zhang1)-[:FOLLOW]->(zhang4)
    create (zhang2)-[:FOLLOW]->(zhang5)
    create (zhang2)-[:FOLLOW]->(zhang6)
    create (zhang3)-[:FOLLOW]->(zhang7)
    create (zhang4)-[:FOLLOW]->(zhang8)
    create (zhang5)-[:FOLLOW]->(zhang9)
    create (zhang7)-[:FOLLOW]->(zhang10)
    
    单向关系
    [r:FOLLOW*0..]即关系从0到无止尽
    in:a -> b
    match p=(a:People) - [r:FOLLOW*0..] -> (b:People) where b.name = 'zhang2' return p
    
    in: 即 a -> b
    out:b -> c
    match p=(b:People) - [rr:FOLLOW*0..] -> (c:People) where b.name = 'zhang2' return p
    
    out: 即 b -> c
    both:a <-> b <-> c
    match p=(a:People) <- [r:FOLLOW*0..] -> (b:People) <- [rr:FOLLOW*0..] -> (c:People) where b.name = 'zhang9' return p
    
    both:即 a <-> b <-> c

    有单双向关系
    CREATE 语句:
    创建节点和单双向关系

    1 <-> 2 <-> 5 -> 9
             -> 6
       -> 3 <-> 7 -> 10
       -> 4 <-> 8   
    
    create (zhang1:User{name:'zhang1'}) 
    create (zhang2:User{name:'zhang2'}) 
    create (zhang3:User{name:'zhang3'})
    create (zhang4:User{name:'zhang4'})
    create (zhang5:User{name:'zhang5'})
    create (zhang6:User{name:'zhang6'})
    create (zhang7:User{name:'zhang7'})
    create (zhang8:User{name:'zhang8'})
    create (zhang9:User{name:'zhang9'})
    create (zhang10:User{name:'zhang10'})
    
    create (zhang1)-[:FOLLOW]->(zhang2)
    create (zhang1)-[:FOLLOW]->(zhang3)
    create (zhang1)-[:FOLLOW]->(zhang4)
    create (zhang2)-[:FOLLOW]->(zhang1)
    create (zhang2)-[:FOLLOW]->(zhang5)
    create (zhang2)-[:FOLLOW]->(zhang6)
    create (zhang3)-[:FOLLOW]->(zhang7)
    create (zhang4)-[:FOLLOW]->(zhang8)
    create (zhang5)-[:FOLLOW]->(zhang2)
    create (zhang5)-[:FOLLOW]->(zhang9)
    create (zhang7)-[:FOLLOW]->(zhang3)
    create (zhang7)-[:FOLLOW]->(zhang10)
    create (zhang8)-[:FOLLOW]->(zhang4)
    
    单双向关系
    MATCH 语句:SQL语句一样
    match (u:User) return u
    match (u:User) where u.name='zhang5' return u
    match p=(u:User)-[r:FOLLOW]->(uu:User) return p
    

    [r:FOLLOW*0..]即关系从0到无止尽
    in:a -> b

    match p=(a:User) - [r:FOLLOW*0..] -> (b:User) where b.name = 'zhang2' return p
    
    in: 即 a -> b
    out:b -> c
    match p=(b:User) - [rr:FOLLOW*0..] -> (c:User) where b.name = 'zhang2' return p
    
    out: 即 b -> c
    both:a <-> b <-> c
    match p=(a:User) <- [r:FOLLOW*0..] -> (b:User) <- [rr:FOLLOW*0..] -> (c:User) where b.name = 'zhang9' return p
    
    both:即 a <-> b <-> c

    相关文章

      网友评论

          本文标题:Neo4j Cyber 使用

          本文链接:https://www.haomeiwen.com/subject/rgyuxctx.html