luceneindextext.java
来自「Lucene+nuctch一书的全部源码 测试源码 和几个简单的项目」· Java 代码 · 共 62 行
JAVA
62 行
package chapter5;
import java.util.Date;
import java.io.IOException;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
public class LuceneIndexText {
private static String Dest_Index_Path = "D:\\workshop\\TextIndex";
static protected String[] keywords = {"001","002","003"};
static protected String[] textdetail = {"记录一","记录二", "记录三"} ;
public static void main(String[] args) {
try {
Date start = new Date();
Analyzer TextAnalyzer = new SimpleAnalyzer();
IndexWriter TextIndex = new IndexWriter(Dest_Index_Path,TextAnalyzer,true);
TextIndex.setUseCompoundFile(true);
for(int i = 0; i < 3 ; i++){
Document document = new Document();
Field field_id = new Field("id", keywords[i],
Field.Store.YES,Field.Index.UN_TOKENIZED);
document.add(field_id);
Field field_content = new Field("content", textdetail[i],
Field.Store.YES,Field.Index.TOKENIZED);
document.add(field_content);
TextIndex.addDocument(document);
}
TextIndex.optimize();
TextIndex.close();
Date end = new Date();
long tm_index = end.getTime() - start.getTime();
System.out.println("Total Time:(ms)");
System.out.println(tm_index);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Index success");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?