Lucene中索引的删除,更新与查找以及恢复(lucene3.5)

package org.itat.text1;
import java.io.File;
import java.io.IOException;

import javax.management.Query;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.Version;


class IndexUtil_11 {
	
	private   String [] ids={"1","2","3","4"};
	private   String [] emails={"[email protected]","[email protected]","[email protected]","[email protected]"};
	private  String [] contents={"Hello world!","lele is so cool!","[email protected]","[email protected]"};
	private   String [] names={"lele!","Tom","zhangsan ","zhaosi"};
	private  int  [] attachs={1,2,3,5};
	private  Directory directory=null;
	
	public  void  index()
	{
		//创建Derectory
		try {
			directory=FSDirectory.open(new File ("G:/Lucene/indext2"));
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		// 创建Writer
		IndexWriter writer=null;
		try {
			writer=new IndexWriter (directory, new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35)));
		Document doc=null;
		for (int i=0;i

package org.itat.text1;
import java.io.IOException;

public class IndexText {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		IndexUtil_11 indextUtil=new IndexUtil_11();
		indextUtil.index();
			indextUtil.delete();
			indextUtil.forceDelete();
			indextUtil.updata();
		//indextUtil.query();
		try {
			//indextUtil.unDelete();
			indextUtil.query();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}

你可能感兴趣的:(Lucene)