<div class="htmledit\_views" id="content\_views"> <p><br></p> <p><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;">由对图数据的处理需求,看到了图数据库(GraphDataBase)这种比较新的数据库模式,并且通过比较发现用的相对多的要属Neo4j了,现在来看网上对Neo4j的介绍还比较少,内容主要来源于三个地方:官方网站</span><a href="http://www.neo4j.org/" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);font-family:simsun;font-size:14px;line-height:21px;" target="\_blank">http://www.neo4j.org/</a><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> </span><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;">;中文社区</span><a href="http://www.neo4j.org.cn/" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);font-family:simsun;font-size:14px;line-height:21px;" target="\_blank">http://www.neo4j.org.cn/</a><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> </span><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;">和Neo4j google网上论坛</span><a href="https://groups.google.com/forum/?fromgroups#!forum/neo4j" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);font-family:simsun;font-size:14px;line-height:21px;" target="\_blank">https://groups.google.com/forum/?fromgroups#!forum/neo4j</a><span style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;">。而中文社区的内容基本上是对官网内容的翻译,可以中英文对照着看,以加快理解。</span></p> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 在各种官方资料中都说Neo4j的性能优良,可以支持几十亿个节点和上百亿的关系,于是怀着兴奋和期望开始了对它的研究。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> Neo4j有两种运行模式,即程序嵌入式模式和服务器模式。对于项目的长期使用来说显然是服务器模式更加适合。所以在对嵌入式模式进行了简单的了解之后就开始对其服务器模式进行研究。对于官网中已经介绍的内容本文就不再赘述了,而目前能搜索到的资料基本上也是这些内容的重复,本文中讲一些我使用过程中遇到的问题和经验。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 首先当然是去官网上下载安装包。我选择的是neo4j-enterprise-1.8.M07-windows版本,按照官网的教程逐步进行安装,启动。这个时候遇到了第一个问题,就是neo4j.bat install执行之后,服务可以安装上去,但是无论如何都无法启动。提示:<span style="color:#FF0000;">失败 1053 服务没有及时响应启动或控制请求</span> 在网上翻看了很多资料,基本上都是修改服务的超时时间,但是此时对这个问题无效。最后在google论坛上看到相似内容,可能是电脑安装的Java jdk版本问题,于是把jdk 1.7 换回到jdk 1.6,再启动果然问题解决了。所以如果要使用Neo4j的服务器模式运行,最好还是首先确定自己电脑安装的是jdk 1.6 </div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 服务运行起来之后就是研究它的功能和用法了。我用的是Java,所以一切内容都是以Java为语言基础的。服务器模式提供了REST API,但是由于水平有限,要自己通过Java使用这些API实在是不容易。于是寻找针对REST API的封装工具。<a href="http://docs.neo4j.org.cn/server-java-rest-client-example.html" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank">http://docs.neo4j.org.cn/server-java-rest-client-example.html</a>这里介绍了如何在Java中使用REST API,其中用到了Jersey,但是在网页上所给的例子中我发现了一个问题,在查询某个点的时候,他的参数用到了之前创建点的时候的临时变量URI firstNode,这就意味着如果所有点已经创建完毕,而我想通过某个点的属性查询到它的话就没有办法了。遗憾的是Java使用REST API这部分只有这一页的例子,其他地方也没有搜索到相关资料。这种方法只能先告一段落。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 还有另外一种方法是通过Java-REST-Binding<a href="http://docs.neo4j.org.cn/rest-clients.html" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank">http://docs.neo4j.org.cn/rest-clients.html</a> 它集成了REST API 可以通过Java远程连接Neo4j服务器GraphDatavaseService gds=new RestGraphDatabase("http://10.108.xxx.xx:7474/db/data");同时还支持Neo4j-core-API,这样就可以像使用嵌入式模式那样的代码形式对数据库进行响应操作,而且嵌入式模式下的代码实例相对较多。这样就可以很方便的进行创建节点,添加属性和关系,查询,创建索引等操作。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 与MongoDB的可视化操作工具MongoVUE相似的是,针对Neo4j也有一个工具-neoclipse。cfeibiao的博客<a href="http://blog.csdn.net/cfeibiao/article/details/6842941" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank">http://blog.csdn.net/cfeibiao/article/details/6842941</a>有对它的基本介绍。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> <a href="http://photo.blog.sina.com.cn/showpic.html#blogid=5fa2a27e0101cku5&url=http://s16.sinaimg.cn/orignal/5fa2a27e4da16c8de6f2f" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank"><img src="http://s16.sinaimg.cn/mw690/5fa2a27e4da16c8de6f2f&690" name="image\_operate\_19481365691791857" alt="Neo4j <wbr>的一些使用心得" title="Neo4j <wbr>的一些使用心得" style="border:0px;list-style:none;"></a></div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 如果你的数据库已经对应点的属性建立了索引,则可以通过某个点的属性值对其进行查询,比如“name”属性的“张三”。另外还支持cyper语言查询。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> 另外一种检测工具就是web控制台,可以通过http://ip地址:7474/webadmin访问。</div> <div style="color:rgb(70,70,70);font-family:simsun;font-size:14px;line-height:21px;"> <a href="http://photo.blog.sina.com.cn/showpic.html#blogid=5fa2a27e0101cku5&url=http://s9.sinaimg.cn/orignal/5fa2a27e4da16e6955598" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank"><img src="http://s9.sinaimg.cn/mw690/5fa2a27e4da16e6955598&690" name="image\_operate\_48791365691917078" alt="Neo4j <wbr>的一些使用心得" title="Neo4j <wbr>的一些使用心得" style="border:0px;list-style:none;"></a><br><br><a href="http://photo.blog.sina.com.cn/showpic.html#blogid=5fa2a27e0101cku5&url=http://s14.sinaimg.cn/orignal/5fa2a27e4da16e9b5fdcd" rel="nofollow" style="text-decoration:none;color:rgb(101,65,46);" target="\_blank"><img src="http://s14.sinaimg.cn/mw690/5fa2a27e4da16e9b5fdcd&690" width="690" height="498" name="image\_operate\_31501365692121429" alt="Neo4j <wbr>的一些使用心得" title="Neo4j <wbr>的一些使用心得" style="border:0px;list-style:none;"></a><br> 最终,一个致命的问题就是速度问题。从现有的MongoDB中把数据转存到Neo4j中,包括查重、设置属性、关系、建立索引等操作,完成一个点需要将近1秒的时间,这是无法忍受的速度。。。<br></div> <br><p></p> </div>