Java lucene 练习


程序有点小问题,不知怎么回事

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!");
}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值