zoukankan      html  css  js  c++  java
  • Lucene 4.0

    关于4.0的Update Index  ,Create Index

        /*
         * Create Index     
         */
        public static void createIndex() throws IOException{
    
            try {
                Directory  directory=FSDirectory.open(new File(indexPath));
                IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_44,analyzer);
                config.setOpenMode(OpenMode.CREATE_OR_APPEND);
                IndexWriter writer=new IndexWriter(directory,config);
                 Document document=new Document();
                 document.add(new org.apache.lucene.document.TextField("content",strBuilder.toString(),Store.YES));
                 document.add(new org.apache.lucene.document.StringField("path", indexPath, Store.YES)); 
                 document.add(new org.apache.lucene.document.StringField("name", "lucene", Store.YES)); 
                 writer.addDocument(document);   
                 writer.close();  
                
            } catch (Exception e) {
                // TODO: handle exception
                System.out.println("created index fail");
                e.printStackTrace();
            }
        }

    /** * update Index * */ public static void updateIndex() throws Exception{ Document document = new Document(); iW_config=new IndexWriterConfig(Version.LUCENE_44,analyzer); iW_config.setOpenMode(OpenMode.CREATE_OR_APPEND); directory=FSDirectory.open(new File(indexPath)); writer=new IndexWriter(directory,iW_config); document=searchDocument("name","lucene"); document.removeField("name"); //更新所以必须在Document中删除了才能奇效 document.add(new StringField("name", "anewfile", Store.YES)); writer.updateDocument(new Term("name","lucene"),document);//此处要指定他的值和类型 writer.commit(); writer.close(); }
  • 相关阅读:
    JavaScript使用技巧精萃
    小谈js事件
    更深入地了解H1N1型流感病毒
    Oracle的一些常用操作
    JS刷新页面
    asp.net Excel导入&导出(转)
    [转]我的敏捷开发实践
    汉字转全拼,简拼组件
    深度复制
    无法删除注册表健值
  • 原文地址:https://www.cnblogs.com/LiMin/p/3430639.html
Copyright © 2011-2022 走看看