日期:2014-05-20 浏览次数:20721 次
//2.3的代码 public static void main(String args[]) throws Exception{ long a=System.currentTimeMillis(); IndexWriter writer=new IndexWriter("index", new KeywordAnalyzer(),true); writer.setMergeFactor(1024); Document doc=null; for(int i=0;i<50000;i++){ doc=new Document(); doc.add(new Field("id","wo"+i,Field.Store.YES,Field.Index.TOKENIZED)); doc.add(new Field("lon","123.1111",Field.Store.YES,Field.Index.TOKENIZED)); writer.addDocument(doc); } writer.optimize(); writer.close(); long b=System.currentTimeMillis(); System.out.println("time:"+(b-a)+"ms"); }
//3.4代码 public static void main(String args[]) throws Exception{ long a=System.currentTimeMillis(); Directory dir=FSDirectory.open(new File("index")); IndexWriterConfig conf=new IndexWriterConfig(Version.LUCENE_34, new KeywordAnalyzer()); conf.setOpenMode(OpenMode.CREATE); LogByteSizeMergePolicy mp=new LogByteSizeMergePolicy(); mp.setMergeFactor(1024); conf.setMergePolicy(mp); IndexWriter writer=new IndexWriter(dir, conf); Document doc=null; for(int i=0;i<50000;i++){ doc=new Document(); doc.add(new Field("id","wo"+i,Field.Store.YES,Field.Index.ANALYZED)); doc.add(new NumericField("lon",Field.Store.YES, true).setDoubleValue(123.1111)); writer.addDocument(doc); } writer.optimize(); writer.close(); long b=System.currentTimeMillis(); System.out.println("time:"+(b-a)+"ms"); }