verboseindexing.java

来自「LuceneInAction配套源码,LuceneInAction是对lucen」· Java 代码 · 共 43 行

JAVA
43
字号
package lia.indexing;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.analysis.SimpleAnalyzer;import java.io.IOException;/** * */public class VerboseIndexing {  private void index() throws IOException {    String dirPath =      System.getProperty("java.io.tmpdir", "tmp") +      System.getProperty("file.separator") + "verbose-index";    Directory dir = FSDirectory.getDirectory(dirPath, true);    IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(),      true);    writer.infoStream = System.out;    for (int i = 0; i < 100; i++) {      Document doc = new Document();      doc.add(Field.Keyword("keyword", "goober"));      writer.addDocument(doc);    }    writer.optimize();    writer.close();  }  public static void main(String[] args) throws IOException {    VerboseIndexing vi = new VerboseIndexing();    vi.index();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?