zoukankan      html  css  js  c++  java
  • LUCENE第一个小程序(有错)

    //照着课本抄的都有错  为什么?、?/???????????

    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;

    import org.apache.lucene.analysis.standard.StandardAnalyzer;
    import org.apache.lucene.document.Document;
    import org.apache.lucene.document.Field;
    import org.apache.lucene.index.CorruptIndexException;
    import org.apache.lucene.index.IndexWriter;
    import org.apache.lucene.index.IndexWriterConfig;
    import org.apache.lucene.store.Directory;
    import org.apache.lucene.store.FSDirectory;
    import org.apache.lucene.store.IndexInput;
    import org.apache.lucene.store.IndexOutput;
    import org.apache.lucene.store.LockObtainFailedException;
    import org.apache.lucene.store.RAMDirectory;
    import org.apache.lucene.util.Version;


    public class HelloLucene {

     /**
      * @param args
      */
     
     
     public static void index()throws IOException
     {
    //  Directory directory=new RAMDirectory() ;
      Directory directory=FSDirectory.open(new File("g:/lucene/first1") );
      IndexWriterConfig iwc=new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35));
      IndexWriter writer=null;
      try
      {writer=new  IndexWriter(directory,iwc);
      Document doc=null;
      File f=new File("g:/lucene");
       for (File file:f.listFiles())
       {
        doc=new Document();
        doc.add(new Field("contend",new FileReader(file)));
        doc.add(new Field("filename",file.getName(),Field.Store.YES,Field.Index.NOT_ANALYZED));
        doc.add(new Field("filepath",file.getAbsolutePath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
        writer.addDocument(doc);
        
        
       }
      }
      catch (CorruptIndexException e)
      {
       e.printStackTrace();
      }
      catch (LockObtainFailedException e)
      {
       e.printStackTrace();
      }
      catch (IOException e)
      {
       e.printStackTrace();
      }
      finally
      {
       if (writer!=null)
       
        writer.close();
      }
     }
      
     
     public static void main(String[] args) {
      // TODO Auto-generated method stub

      try {
       index();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      
     }

    }

    
    


  • 相关阅读:
    [luoguP1196] 银河英雄传说(并查集)
    [luoguP1111] 修复公路(并查集)
    [luoguP2387] 魔法森林(LCT + 并查集)
    [BZOJ2594] [Wc2006]水管局长数据加强版(LCT + kruskal + 离线)
    [luoguP2045] 方格取数加强版(最小费用最大流)
    [BZOJ2843] 极地旅行社(LCT)
    [luoguP3690] 【模板】Link Cut Tree
    [luoguP3203][HNOI2010]BOUNCE 弹飞绵羊(LCT)
    [luoguP1901] 发射站(单调栈)
    codeforces Round#381 div2
  • 原文地址:https://www.cnblogs.com/lixingle/p/3313049.html
Copyright © 2011-2022 走看看