private IndexWriter createWriter() throws IOException {
    IndexWriter writer = new IndexWriter(dir, false, null, new KeepOnlyLastCommitDeletionPolicy());
    writer.setUseCompoundFile(false);

    if (iconf != null) {
      int maxFieldLength = iconf.getIndexMaxFieldLength();
      if (maxFieldLength > 0) {
        writer.setMaxFieldLength(maxFieldLength);
      }
    }

    return writer;
  }
示例#2
0
 public static void IndexCreate() throws Exception {
   String path = "D:\\Lucene Document";
   directory = FSDirectory.getDirectory(path);
   Analyzer analyzer = new StandardAnalyzer();
   IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
   iwriter.setMaxFieldLength(25000);
   // make a new, empty document
   Document doc = new Document();
   String text = "This is the text to be indexed.";
   doc.add(new Field("fieldname", text, Field.Store.YES, Field.Index.TOKENIZED));
   iwriter.addDocument(doc);
   iwriter.optimize();
   iwriter.close();
 }