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(); }
  • 相关阅读:
    linux内核——进程切换宏switch_to
    android源码目录结构详解
    SRM 390(1-250pt)
    SRM 391(1-250pt)
    CodeForces 221(div 2)
    SRM 407(1-250pt, 1-500pt)
    SRM 392(1-250pt)
    SRM 393(1-250pt)
    CodeForces 220(div 2)
    SRM 406(1-250pt, 1-500pt)
  • 原文地址:https://www.cnblogs.com/LiMin/p/3430639.html
Copyright © 2011-2022 走看看