【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:BasicIndexer.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
//BasicIndexer.java
package tianen;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
public class BasicIndexer
{
public static void main(String[] args) throws java.io.IOException
{
String indexPath = "index";
//IndexWriter
IndexWriter writer = new IndexWriter(indexPath,new StandardAnalyzer());
//Document
Document doc = new Document();
//Field -title
String title = "i love china";
Field field = new Field("title",title ,Field.Store.YES, Field.Index.TOKENIZED);
//add field
doc.add(field);
//Field -content
String content = "i love you, my mother land! ";
field = new Field("content", content ,Field.Store.YES, Field.Index.TOKENIZED);
//add field
doc.add(field);
//add document
writer.addDocument(doc);
//close IndexWriter
writer.close();
//message
System.out.println("Index Created!");
}
}