程序有点小问题,不知怎么回事
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
public class ThreeIndexer {
public static void main(String[]args)
{
String indexPath="three";
//创建IndexWriter
IndexWriter writer =new IndexWriter(indexPath,new StandardAnalyzer());
/**********************************************************************/
//创建Document--1
Document doc =new Document();
//创建Field-title
String title="i love china";
Field field=new Field("title",title,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建field-content
String content="i love you,my motherland!";
field=new Field("content",content,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建Field-time
String time="2007-05-31";
field=new Field("time",time,Field.Store.YES,Field.Index.NO);
//添加field
doc.add(field);
//添加document
writer.addDocument(doc);
/*************************************************************************/
//创建Document--2
doc=new Document();
//创建Field-title
title="i love mom";
field=new Field("title",title,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建Field-content
content="i love my mother";
field=new Field("title",title,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建Field-time
time="2007-05-31";
field=new Field("time",time,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//添加document
writer.addDocument(doc);
/**************************************************************************/
//创建Document--3
doc=new Document();
//创建Field-title
title="i love xiaoyue";
field=new Field("title",title,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建Field-content
content="i love you,my wife!";
field=new Field("content",content,Field.Store.YES,Field.Index.TOKENIZED);
//添加field
doc.add(field);
//创建Field-time
time="2007-05-31";
field=new Field("time",time,Field.Store.YES,Field.Index.NO);
//添加field
doc.add(field);
//添加document
writer.addDocument(doc);
/**********************************************************************************/
//关闭 IndexWriter
writer.close();
//提示
System.out.println("Index Three Created!");
}
}