MoveLuceneSmall
packagecom.yulong.lucene.biz;
importjava.io.File;
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
*/
publicclassMoveLuceneSmall{
privateStringpath="";
publicMoveLuceneSmall(Stringpath){
this.path=RequestUtil.ChangePath(path);
this.move();
}
/**
*开始转移
*
*@return
*/
@SuppressWarnings("deprecation")
publicbooleanmove(){
IndexWriteriw=null;
try{
Filefile=newFile(path+"small/");
if(file.exists()){
try{
Directorydirectory=FSDirectory.open(file);
iw=LuceneContacts.iwpool.get(path+"index/",this.toString());
if(iw!=null){
iw.addIndexes(newDirectory[]{directory});
IndexWriteriwcc=LuceneContacts.iwpool.get(path+"small/",this.toString());
iwcc.deleteAll();
iwcc.close();
}
}catch(Exceptione){
}
}
iw.close();
}catch(Exceptione){
e.printStackTrace();
returnfalse;
}
LuceneContacts.iwpool.over(path+"index/",this.toString());
LuceneContacts.iwpool.over(path+"small/",this.toString());
returntrue;
}
}