neo4j中索引的使用
来源:互联网 发布:mac平面设计用什么软件 编辑:程序博客网 时间:2024/05/29 14:53
neo4j可以对node和relationship中的属性建立索引,索引中的node(relationship)和属性对key-value为多对多的关系。一个node(relationship)可以在某索引中存储多个属性对,一个属性对也可以对应到多个node(relationship)。
代码:
Node node1 = graphDb.createNode(); node1.setProperty("name","easypoint"); Node node2 = graphDb.createNode(); node2.setProperty("name","csdn"); nodeIndex.add(node1,"name",node1.getProperty("name")); nodeIndex.add(node1,"name","haha"); nodeIndex.add(node2,"name",node2.getProperty("name")); nodeIndex.add(node2,"name","haha"); for(Node node :nodeIndex.get("name","haha")){ System.out.println(node.getProperty("name")); }结果:
easypointcsdn
在neo4j中,索引可以分为两类:neo4j本身既是关于relationship的索引实现;基于独立索引引擎,如Apache Lucene的索引机制。通常情况下,我们所说的索引指第二种情况。按照索引的对象可以将索引分为两类:基于node的索引和基于relationship的索引。
与oracle等关系型数据库不同的是,neo4j中索引的维护由用户自行管理(索引内容的增删改)。索引的维护必须在事务范围内。每个索引具有一个名称,neo4j根据名称来查找或者创建索引。
维护索引时,有一点需要特别注意:更新索引时,需要手工删除对应的更新项,然后在添加更新后的项; 如下所示:
// create a node with a property// so we have something to update later onNode fishburn = graphDb.createNode();fishburn.setProperty( "name", "Fishburn" );// index itactors.add( fishburn, "name", fishburn.getProperty( "name" ) );// update the index entry// when the property value changesactors.remove( fishburn, "name", fishburn.getProperty( "name" ) );fishburn.setProperty( "name", "Laurence Fishburn" );actors.add( fishburn, "name", fishburn.getProperty( "name" ) );
如果,不删除旧项,则会同时存在指向fishburn的两个key-value。
索引的查询可以使用GET方法,也可以使用QUERY方法,相对与get,query方法功能更强大一些。get方法进行精确的key-value匹配;QUERY
Relationship persephone = roles.get( "name", "Persephone" ).getSingle();
for ( Node movie : movies.query( "title:*Matrix* AND year:1999" ) ){// This will return "The Matrix" from 1999 only.}
创建索引时,通过api可以制定索引的配置选项。如下所示,配置索引支持fulltext检索
Index<Node> fulltextMovies = index.forNodes( "movies-fulltext", stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext") );
Node node1 = graphDb.createNode(); node1.setProperty("name","easypoint and abb"); fulltextMovies.add( node1,"name",node1.getProperty("name")); for(Node node :fulltextMovies.query( "name", "and" )){ System.out.println(node.getProperty("name")); }
总结:neo4j提供了索引机制,与关系数据库相比,需要编程人员干预的内容较多,也正是因此,其灵活性是比较强的,但无疑增加了程序人员的工作量。
- neo4j中索引的使用
- neo4j的使用一
- neo4j的使用二
- neo4j的使用感悟
- neo4j的使用
- 在Django中使用Neo4j
- 在 Python 中使用 Neo4j
- 图数据库Neo4J的使用
- 图数据库Neo4J的使用
- Neo4j 的一些使用心得
- Neo4j的Rest接口使用
- 使用python的 neo4j.v1出现无法连接Neo4j问题
- 中国银行图谱中neo4j使用备份
- neo4j使用
- Neo4j 节点索引NodeIndex
- Neo4j:Index索引
- Neo4j使用时的一些体会
- 图数据库之neo4j-jdbc的使用
- Breadth-first traverse
- 【中缀转换成后缀或者前缀的思想、过程以及算法实现】
- PHP "十二五" 简易 BLOG 代码- 未测试- 03
- matplotlib绘制简单图
- PHP "十二五" 简易 BLOG 代码- 未测试- 04
- neo4j中索引的使用
- PHP "十二五" 简易 BLOG 代码- 未测试- 05
- js中的replace的使用方法
- VS debug下为什么多此一举jmp函数地址?
- TPROXY之殇-NAT设备加代理的恶果
- (笔记)spss的非参数检验
- Android照片墙应用实现,再多的图片也不怕崩溃
- Android应用程序调试问题总结
- hex文件格式