---
title: "MoveLuceneSmall"
author: "xiaowei2002"
date: "2014-11-06T10:01:01Z"
tags: []
categories: ["Web前端"]
slug: "movelucenesmall"
draft: false
lastmod: "2014-11-06T10:01:01Z"
id: 2152931
url: "https://xiaowei2002.iteye.com/blog/2152931"
---

package com.yulong.lucene.biz;

import java.io.File;

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 MoveLuceneSmall {
	private String path = "";

	public MoveLuceneSmall(String path) {
		this.path = RequestUtil.ChangePath(path);
		this.move();
	}

	/**
	 * 开始转移
	 *
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public boolean move() {
		IndexWriter iw = null;
		try {
			File file = new File(path+"small/");
			if (file.exists()) {
				try{
					Directory directory = FSDirectory.open(file);
					iw =LuceneContacts.iwpool.get(path +"index/", this.toString());
					if(iw != null){
						iw.addIndexes(new Directory{directory});
						IndexWriter iwcc = LuceneContacts.iwpool.get(path +"small/", this.toString());
						iwcc.deleteAll();
						iwcc.close();
					}
				}catch (Exception e) {
				}
			}
			iw.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		LuceneContacts.iwpool.over(path +"index/", this.toString());
		LuceneContacts.iwpool.over(path +"small/", this.toString());
		return true;
	}

}