ITeye博客

MoveLuceneRebuild

xiaowei2002 · 2014-11-06 09:59 · luence · Web前端 · Markdown

package com.yulong.lucene.biz;

import java.io.File; import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory;

import com.yulong.lucene.core.LuceneContacts; import com.yulong.lucene.util.RequestUtil;

/**

  • LUCENE小文件移动到大文件中的任务调度 *
  • @author fyh */ public class MoveLuceneRebuild { private String path = "";

// public MoveLuceneRebuild(String path) { // this.path = RequestUtil.ChangePath(path); // this.move(); // }

/**
 * 开始转移
 *
 * @return
 */
@SuppressWarnings("deprecation")
public boolean move(String path) {
	this.path = RequestUtil.ChangePath(path);
	IndexWriter iw = null;
	IndexWriter iwcc = null;
	try {
		File file = new File(path+"rebuild/");
		if (file.exists()) {
			try{
				Directory directory = FSDirectory.open(file);
				iw = LuceneContacts.iwpool.get(path +"index/", this.toString());
				iw.deleteAll();
				if(iw != null){
					iw.addIndexes(new Directory{directory});
					iwcc = LuceneContacts.iwpool.get(path +"rebuild/", this.toString());
					iwcc.deleteAll();

// iwcc.close(); } }catch (Exception e) { } } // iw.close();

	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}finally{
		try {
			if(iwcc!=null){
				iwcc.close();					
			}
			if(iw!=null){
				iw.close();
			}
		} catch (CorruptIndexException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	return true;
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。