Neo4j是一個Java開發的圖數據庫,它將結構化數據存儲在網絡(從數學角度叫作圖)上而不是表中。相對於關係數據庫來講,圖數據庫善於處理大量複雜、互鏈接、低結構化的數據,這些數據變化迅速,須要頻繁的查詢——在關係數據庫中,這些查詢會致使大量的錶鏈接,所以會產生性能上的問題。Neo4j重點解決了擁有大量鏈接的傳統RDBMS在查詢時出現的性能衰退問題。Neo4j還提供了很是快的圖算法、推薦系統和OLAP風格的分析,而這一切在目前的RDBMS系統中都是沒法實現的。它提供了普遍使用的REST接口,可以方便地集成到基於JAVA、PHP、.NET和JavaScript的環境裏。html
CREATE (ee:員工 { 姓名: "張勇", 來自: "中國" , 年齡 : 99 })
本身動手寫個Demo試試前端
CREATE (p1:Person {name:'胡興炯', born:1991, interest:'mac,ios,旅遊', goodat:'java,swift,objectiveC'}) CREATE (p2:Person {name:'張勇', born:1990, interest:'android', goodat:'java,android'}) CREATE (p3:Person {name:'成文龍', born:1990, interest:'linux,hadoop', goodat:'linux,java,android'}) CREATE (p4:Person {name:'王昕', born:1978, interest:'wpf,noSQL,旅遊', goodat:'java,c#'}) CREATE (p5:Person {name:'周開琪', born:1977 , interest:'管理', goodat:'管理,'}) CREATE (p6:Person {name:'徐錦亮', born:1985, interest:'前端', goodat:'前端,html5'}) CREATE (p8:Person {name:'徐輝霞', born:1990, interest:'管理,旅遊', goodat:'管理,採購'}) CREATE (p9:Person {name:'黃廷鵬', born:1992, interest:'OA', goodat:'java'}) CREATE (p10:Person {name:'史樂樂', born:1991, interest:'OA,旅遊', goodat:'管理'}) CREATE (p1)-[:認識]->(p2) CREATE (p1)-[:認識]->(p3) CREATE (p1)-[:認識]->(p4) CREATE (p1)-[:認識]->(p5) CREATE (p1)-[:認識]->(p9) CREATE (p2)-[:認識]->(p1) CREATE (p2)-[:認識]->(p3) CREATE (p2)-[:認識]->(p4) CREATE (p2)-[:認識]->(p5) CREATE (p2)-[:認識]->(p9) CREATE (p3)-[:認識]->(p1) CREATE (p3)-[:認識]->(p2) CREATE (p3)-[:認識]->(p4) CREATE (p3)-[:認識]->(p5) CREATE (p3)-[:認識]->(p9) CREATE (p4)-[:認識]->(p1) CREATE (p4)-[:認識]->(p2) CREATE (p4)-[:認識]->(p3) CREATE (p4)-[:認識]->(p5) CREATE (p4)-[:認識]->(p9) CREATE (p5)-[:認識]->(p1) CREATE (p5)-[:認識]->(p2) CREATE (p5)-[:認識]->(p3) CREATE (p5)-[:認識]->(p4) CREATE (p5)-[:認識]->(p6) CREATE (p5)-[:認識]->(p8) CREATE (p5)-[:管理]->(p1) CREATE (p5)-[:管理]->(p2) CREATE (p5)-[:管理]->(p3) CREATE (p5)-[:管理]->(p4) CREATE (p5)-[:管理]->(p6) CREATE (p6)-[:認識]->(p5) CREATE (p6)-[:認識]->(p4) CREATE (p6)-[:夫妻]->(p8) CREATE (p9)-[:認識]->(p1) CREATE (p9)-[:認識]->(p2) CREATE (p9)-[:認識]->(p3) CREATE (p9)-[:認識]->(p10) CREATE (p9)-[:單相思]->(p10) CREATE (p10)-[:認識]->(p9)
運行完上面腳本的效果
html5
MATCH (n:Person ) WHERE n.goodat =~ '.*管理.*' return n;
MATCH (n:Person { name: '成文龍' })-[:認識]-(neighbors) RETURN n,neighbors
MATCH (n:Person)-[:單相思]-(neighbors) RETURN n,neighbors
MATCH (n:Person { name: '周開琪' })-[:管理]-(neighbors) RETURN n,neighbors
MATCH (n:Person { name: '徐輝霞' })-[:認識*1..2]-(neighbors) RETURN n, collect(DISTINCT neighbors)
MATCH (n:Person { name: '徐輝霞' })-[:認識*1..3]-(neighbors) RETURN n, collect(DISTINCT neighbors)
MATCH p=allShortestPaths( (a:Person { name: '徐錦亮' })-[:認識*..4]-(b:Person { name: '史樂樂'}) ) RETURN p
MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r