首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

图形数据库之-neo4j(非关系型数据库)

2013-10-25 
图形数据库之---neo4j(非关系型数据库)Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上

图形数据库之---neo4j(非关系型数据库)

Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中。Neo4j也可以被看作是一个高性能的图引擎,该引擎具有成熟数据库的所有特性。程序员工作在一个面向对象的、灵活的网络结构下而不是严格、静态的表中——但是他们可以享受到具备完全的事务特性、企业级的数据库的所有好处。

Neo4j因其嵌入式、高性能、轻量级等优势,越来越受到关注。

图形数据结构

在一个图中包含两种基本的数据类型:Nodes(节点) 和 Relationships(关系)。Nodes 和 Relationships 包含key/value形式的属性。Nodes通过Relationships所定义的关系相连起来,形成关系型网络结构。


     neo4j是一种图数据库,同时它也是一种嵌入式数据库。它对图数据是以节点和边(关系)模式进行存储。每个节点可以包含一系列信息,通过Node类里面的setProperty()方法对节点信息进行存储,Node也可以使用createRelationshipTo()方法实现个节点和其他节点的联系,并且该方法返回的是一个Relationship对象,我们也可以对Relationship设置属性,也就是节点和节点之间的关系属性。什么叫关系属性?例如:person1àperson2,person1和person2的关系可以是朋友也可以是同学还可以是亲人,这里的朋友、同学、亲人就是这里的Relationship的属性。那么关系属性就是描叙两个节点之间的关系类型。这就方便在对节点进行查找的时候对节点进行过滤。



neo4j数据库中的节点类似关系型数据库中的表。neo4j节点之间的关系类似关系型数据库中的2表之间的第三张表,neo4j数据库的节点之间的关系上也可以保存一些2者之间关系的属性键值对。同样,可以为每种关系创建一个名字,把关系归类管理。图形数据库比关系型性能好很多,操作性很好,可以灵活的控制,根据neo4j中Node的不同,我们可以赋予不同的属性

http://docs.neo4j.org/refcard/2.0/

STARTSTARTn=node(*)STARTn=node({ids})STARTn=node({id1}), m=node({id2})STARTn=node:nodeIndexName(key={value})node_auto_indexfor the automatic index.

MATCHMATCH(n:Person)-[:KNOWS]->(m:Person)WHEREn.name="Alice"START clause is required then.

MATCH(n)-->(m)MATCH except the ones containing property maps.

MATCHp = (n)-->(m)p.

WHEREWHEREn.property <> {value}Predicatesn.property <> {value}has(n.property)n.number >= 1 ANDn.number <= 10n:PersonidentifierISNULLNULL.

NOThas(n.property)ORn.property = {value}TRUE.

n.property = {value}NULL, which is only equal to NULL.

n.property =~ "Tob.*"(n)-[:KNOWS]->(m)NOT(n)-[:KNOWS]->(m)(n)-[:KNOWS]->(m) from the result.

n.propertyIN[{value1}, {value2}]Predicate Functionsall(xINcollection WHEREhas(x.property))true if the predicate is TRUE for all elements of the collection.

any(xINcollection WHEREhas(x.property))true if the predicate is TRUE for at least one element of the collection.

none(xINcollection WHEREhas(x.property))TRUE if the predicate is FALSE for all elements of the collection.

single(xINcollection WHEREhas(x.property))TRUE if the predicate is TRUE for exactly one element in the collection.

Scalar Functionslength(collection)type(a_relationship)startNode(a_relationship)endNode(a_relationship)coalesce(n.property, {defaultValue})NULL expression.

head(collection)last(collection)timestamp()id(node_or_relationship)String Functionsstr({expression})replace({original}, {search}, {replacement})search with replacement. All arguments are be expressions.

substring({original}, {begin}, {sub_length})sub_length argument is optional.

left({original}, {sub_length}),  right({original}, {sub_length})trim({original}),ltrim({original}),  rtrim({original})upper({original}),lower({original})RETURNRETURN*RETURNn AScolumnNameRETURNDISTINCT nORDERBY n.propertyORDERBY n.property DESCSKIP{skip_number}LIMIT{limit_number}SKIP{skip_number} LIMIT{limit_number}WITHMATCH(user)-[:FRIEND]-(friend)WHEREuser.name = {name}WITHuser, count(friend)ASfriendsWHEREfriends > 10RETURNuserWITH syntax is similar to RETURN. It separates query parts explicitly, allowing you to declare which identifiers to carry over to the next part.

MATCH(user)-[:FRIEND]-(friend)WITHuser, count(friend)ASfriendsORDERBY friends DESCSKIP1 LIMIT3RETURNuserORDER BY, SKIP, LIMIT with WITH.

CASECASEn.eyes WHEN'blue' THEN 1 WHEN'brown' THEN 2 ELSE3ENDTHEN value from the matching WHEN value. TheELSE value is optional, and substituted for NULL if missing.

CASE WHENn.eyes = 'blue'THEN 1 WHENn.age < 40 THEN2 ELSE3ENDTHEN value from the first WHEN predicate evaluating to TRUE. Predicates are evaluated in order.

Collection Functionslabels(n)nodes(path)relationships(path)extract(xINcoll | x.prop)filter(xINcoll WHEREx.prop <> {value})TRUE.

tail(coll)range({first_num}, {last_num}, {step})step argument is optional.

reduce(s = "", n INcoll | s + n.prop)FOREACH(n INcoll | SETn.marked = TRUE)Aggregationcount(*)count(identifier)NULL values.

count(DISTINCTidentifier)DISTINCTmodifier, which removes duplicates from the values.

sum(n.property)avg(n.property)max(n.property)min(n.property)collect(n.property)NULL.

percentile_disc(n.property, {percentile})percentile argument is from 0.0to 1.0.

percentile_cont(n.property, {percentile})stdev(n.property)stdevp(n.property)(CREATE[UNIQUE] | MERGE)*[SET|DELETE|FOREACH]*[RETURN[ORDERBY] [SKIP] [LIMIT]][START][MATCH][WHERE][WITH[ORDERBY] [SKIP] [LIMIT]][CREATE[UNIQUE]|MERGE]*[SET|DELETE|FOREACH]*[RETURN[ORDERBY] [SKIP] [LIMIT]]CREATECREATE(n {name: {value}})CREATE(n {map})CREATE(n {collectionOfMaps})CREATE(n)-[r:KNOWS]->(m)CREATE(n)-[:LOVES {since: {value}}]->(m)CREATE UNIQUECREATEUNIQUE    (n)-[:KNOWS]->(m {property: {value}})MERGEMERGE(n:Person {property: {value}})ONCREATE n SETn.created = timestamp()ONMATCH  n SETn.access  = n.access+1ON CREATE n and ON MATCH n for conditional updates.

SETSETn.property={value}SETn={map}SETn:PersonPerson to a node.

DELETEDELETEn, rREMOVEn:Personn.

REMOVEn.propertyINDEXCREATEINDEX ON :Person(name)Person and property name.

DROPINDEX ON :Person(name)Person and property name.

MATCH(n:Person) WHEREn.name = {value}lower(n.name) = {value} will not use an index.

Mathematical Functionsabs({expr})rand()round({expr})floor({expr})ceil({expr})sqrt({expr})sign({expr})0 if zero, -1 if negative, 1 if positive.

sin({expr})cos, tan, cot, asin, acos,atan, atan2({y-expr}, x-expr}).

degrees({expr}),radians({expr}),pi()radians for the reverse. pi for π.

log10({expr}),log({expr}),exp({expr}),e()e to the power of the parameter. Value of e.


热点排行