关于4.0的Update Index  ,Create Index

  1. /*
  2. * Create Index
  3. */
  4. public static void createIndex() throws IOException{
  5.  
  6. try {
  7. Directory directory=FSDirectory.open(new File(indexPath));
  8. IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_44,analyzer);
  9. config.setOpenMode(OpenMode.CREATE_OR_APPEND);
  10. IndexWriter writer=new IndexWriter(directory,config);
  11. Document document=new Document();
  12. document.add(new org.apache.lucene.document.TextField("content",strBuilder.toString(),Store.YES));
  13. document.add(new org.apache.lucene.document.StringField("path", indexPath, Store.YES));
  14. document.add(new org.apache.lucene.document.StringField("name", "lucene", Store.YES));
  15. writer.addDocument(document);
  16. writer.close();
  17.  
  18. } catch (Exception e) {
  19. // TODO: handle exception
  20. System.out.println("created index fail");
  21. e.printStackTrace();
  22. }
  23. }
  1. /**
  2. * update Index
  3. * */
  4. public static void updateIndex() throws Exception{
  5. Document document = new Document();
  6. iW_config=new IndexWriterConfig(Version.LUCENE_44,analyzer);
  7. iW_config.setOpenMode(OpenMode.CREATE_OR_APPEND);
  8. directory=FSDirectory.open(new File(indexPath));
  9. writer=new IndexWriter(directory,iW_config);
  10. document=searchDocument("name","lucene");
  11. document.removeField("name"); //更新所以必须在Document中删除了才能奇效
  12. document.add(new StringField("name", "anewfile", Store.YES));
  13. writer.updateDocument(new Term("name","lucene"),document);//此处要指定他的值和类型
  14. writer.commit();
  15. writer.close();
  16. }

Lucene 4.0的更多相关文章

  1. 关于Lucene 3.0升级到Lucene 4.x 备忘

    最近,需要对项目进行lucene版本升级.而原来项目时基于lucene 3.0的,很古老的一个版本的了.在老版本中中,我们主要用了几个lucene的东西: 1.查询lucene多目录索引. 2.构建R ...

  2. Lucene 6.0下使用IK分词器

    Lucene 6.0使用IK分词器需要修改修改IKAnalyzer和IKTokenizer. 使用时先新建一个MyIKTokenizer类,一个MyIkAnalyzer类: MyIKTokenizer ...

  3. Lucene 4.0 正式版发布,亮点特性中文解读[转]

    http://blog.csdn.net/accesine960/article/details/8066877 2012年10月12日,Lucene 4.0正式发布了(点击这里下载最新版),这个版本 ...

  4. lucene 3.0.2 + 多文件夹微博数据(时间,微博)构建索引

    package lia.meetlucene; import java.io.File; import java.io.IOException; import java.util.LinkedList ...

  5. lucene 3.0.2 search 各种各样的Query类型

    http://blog.sina.com.cn/s/blog_61d2047c010195mo.html     lucene的这种各种各样的查询类型 1.TermQuery       最简单的Qu ...

  6. lucene 3.0.2 中文分词

    package lia.meetlucene; import java.io.IOException; import java.io.Reader; import java.io.StringRead ...

  7. lucene 3.0.2 操作进阶

    转自:Bannings http://blog.csdn.net/zhangao0086/article/details/ Analyzer(分词器) 分词器能以某种规则对关键字进行分词,将分好的词放 ...

  8. lucene 3.0.2 搜索

    1.lucene 词频 转载:http://mxdxm.iteye.com/blog/989031 lucene in action作为action系列,确实坚持了其实用性的特色.全书花了很大的篇幅来 ...

  9. lucene 4.0学习

    一:官方文件 http://lucene.apache.org/core/4_0_0/ ps:网上参考文章:http://www.cnblogs.com/xing901022/p/3933675.ht ...

随机推荐

  1. Joy of Programming: Understanding Bit-fields in C

    转:http://www.linuxforu.com/2012/01/joy-of-programming-understanding-bit-fields-c/ By S.G. Ganesh on ...

  2. http协议学习(一)http状态

    整理了一个脑图,算作是<图解HTTP>的读书笔记,这本书有很多插图,适合初学者入门理解. 讲解网络协议的书不多 其中两本被人们奉为圣经  <TCP/IP详解 卷一> <H ...

  3. docker 连接容器

    1.通过端口映射 sudo docker run -d -P training/webapp python app.py 容器有一个内部网络和IP地址(在使用Docker部分我们使用docker in ...

  4. Border绘制虚线框(转)

    <Grid> <Border HorizontalAlignment="Center" VerticalAlignment="Center" ...

  5. iOS- SQLite3的基本使用

    iOS- 简单说说iOS移动客户端SQLite3的基本使用  1.为什么要使用SQLite3?   •大量数据需要存储 •管理数据,存储数据   SQLite是一种关系型数据库(也是目前移动客户端的主 ...

  6. Wamp,XAMPP 无法启动,端口未占用的故障处理

    打开服务管理里:Service.msc 找到服务:WinHttpAutoProxySvc(WinHTTP 实现了客户端 HTTP 堆栈并向开发人员提供 Win32 API 和 COM 自动化组件以供发 ...

  7. C# 使用代码来操作 IIS

    由于需要维护网站的时候,可以自动将所有的站点HTTP重定向到指定的静态页面上. 要操作 IIS 主要使用到的是“Microsoft.Web.Administration.dll”. 该类库不可以在引用 ...

  8. SQL查询中的in与join效率比较

    大多数情况下,程序员比较喜欢使用in来查询符合某些条件的数据,最近在查询某个角色有哪些用户的方法中,使用了in语句: ) FROM baseuser AND BaseUser.Id IN (SELEC ...

  9. Android下拉刷新-SwipeRefreshLayout,RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout)

    SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包下,不过我们需要升级supportlibr ...

  10. ubuntu 换源

    经过自己一番折腾后,发现用这个方法换源最简单.直接. sudo vi /etc/apt/sources.list 把sources.list里面的内容全部替换为一下内容 deb http://mirr ...