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之DOM性能优化
    移动端内容超出容器滑动会卡的解决办法
    Oracle表、列、约束的操作
    Oracle INTERVAL DAY TO SECOND数据类型
    linux下mysql的root密码忘记解决方法
    Oracle:grouping和rollup
    Oracle 中的Pivoting Insert用法
    使用INTERVAL YEAR TO MONTH类型
    SQL:deferrable initially deferred
    ORA-25154/ORA-01748
  • 原文地址:https://www.cnblogs.com/LiMin/p/3430639.html
Copyright © 2011-2022 走看看