MoveLuceneRebuild
packagecom.yulong.lucene.biz;
importjava.io.File;
importjava.io.IOException;
importorg.apache.lucene.index.CorruptIndexException;
importorg.apache.lucene.index.IndexWriter;
importorg.apache.lucene.store.Directory;
importorg.apache.lucene.store.FSDirectory;
importcom.yulong.lucene.core.LuceneContacts;
importcom.yulong.lucene.util.RequestUtil;
/**
*LUCENE小文件移动到大文件中的任务调度
*
*@authorfyh
*/
publicclassMoveLuceneRebuild{
privateStringpath="";
//publicMoveLuceneRebuild(Stringpath){
//this.path=RequestUtil.ChangePath(path);
//this.move();
//}
/**
*开始转移
*
*@return
*/
@SuppressWarnings("deprecation")
publicbooleanmove(Stringpath){
this.path=RequestUtil.ChangePath(path);
IndexWriteriw=null;
IndexWriteriwcc=null;
try{
Filefile=newFile(path+"rebuild/");
if(file.exists()){
try{
Directorydirectory=FSDirectory.open(file);
iw=LuceneContacts.iwpool.get(path+"index/",this.toString());
iw.deleteAll();
if(iw!=null){
iw.addIndexes(newDirectory[]{directory});
iwcc=LuceneContacts.iwpool.get(path+"rebuild/",this.toString());
iwcc.deleteAll();
//iwcc.close();
}
}catch(Exceptione){
}
}
//iw.close();
}catch(Exceptione){
e.printStackTrace();
returnfalse;
}finally{
try{
if(iwcc!=null){
iwcc.close();
}
if(iw!=null){
iw.close();
}
}catch(CorruptIndexExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returntrue;
}
}