lucene入门-复杂索引建立

一个document包括多个field,以一个document为了一个单元建立索引,下例包括2个document:

package bindex;
import java.io.IOException;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;

 


public class basicindexer {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
        String indexPath ="indexes";
      try {
  IndexWriter indexWriter = new IndexWriter(indexPath,new StandardAnalyzer());
        Document doc=new Document();
  String blogtitle="计算机软件技术与理论交流";
  String blogauthor="深未来工作室(deepfuture@qq.com)-深度创造未来";
  String blogurl="http://blog.163.com/sukerl@126/";
  Field field=new Field("title",blogtitle,Field.Store.YES,Field.Index.TOKENIZED);
  doc.add(field);
  field=new Field("author",blogtitle,Field.Store.YES,Field.Index.TOKENIZED);
  doc.add(field);
  field=new Field("url",blogurl,Field.Store.YES,Field.Index.NO);
  doc.add(field);  
  indexWriter.addDocument(doc);
  doc=new Document();
  blogtitle="深未来工作室 ";
  blogauthor="深未来工作室(deepfuture@qq.com)-深度创造未来";
  blogurl="http://1121240010.qzone.qq.com/";
  field=new Field("title",blogtitle,Field.Store.YES,Field.Index.TOKENIZED);
  doc.add(field);
  field=new Field("author",blogtitle,Field.Store.YES,Field.Index.TOKENIZED);
  doc.add(field);
  field=new Field("url",blogurl,Field.Store.YES,Field.Index.NO);
  doc.add(field);  
  indexWriter.addDocument(doc);  
  indexWriter.close();
  System.out.println("OK!");
 } catch (CorruptIndexException e) {
   // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (LockObtainFailedException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值