|
|
@@ -105,9 +105,14 @@ public class IndexServiceImpl implements IndexService {
|
|
|
*/
|
|
|
private boolean creatingIndex = false;
|
|
|
|
|
|
+ /**
|
|
|
+ * 从数据库获取数据时的分页大小
|
|
|
+ */
|
|
|
private static final int PAGE_SIZE = 1000;
|
|
|
|
|
|
- // 单个文件存储的最大数据数目
|
|
|
+ /**
|
|
|
+ * 单个文件存储的最大数据数目,需是PAGE_SIZE的整数倍
|
|
|
+ */
|
|
|
public static final int SINGLE_FILE_MAX_SIZE = 100000;
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(IndexServiceImpl.class);
|
|
|
@@ -389,13 +394,22 @@ public class IndexServiceImpl implements IndexService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Long downloadComponentDataFromDatabase() {
|
|
|
+ public Long downloadComponentDataFromDatabase(Integer startFileIndex) {
|
|
|
+ int fileIndex = 1;
|
|
|
+ if (startFileIndex != null) {
|
|
|
+ if (startFileIndex < 1) {
|
|
|
+ throw new SearchException("startFileIndex需大于1");
|
|
|
+ } else {
|
|
|
+ fileIndex = startFileIndex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Long startTime = new Date().getTime();
|
|
|
logger.info("下载器件... ");
|
|
|
|
|
|
// 分页获取数据
|
|
|
PageParams pageParams = new PageParams();
|
|
|
- pageParams.setPage(1);
|
|
|
+ pageParams.setPage((fileIndex - 1) * SINGLE_FILE_MAX_SIZE / PAGE_SIZE + 1);
|
|
|
pageParams.setCount(PAGE_SIZE);
|
|
|
PageInfo pageInfo = new PageInfo(pageParams);
|
|
|
Page<ComponentSimpleInfo> pageResult = componentDao.findAll(pageInfo);
|
|
|
@@ -405,7 +419,6 @@ public class IndexServiceImpl implements IndexService {
|
|
|
logger.info("发现数据:" + totalElements + "条");
|
|
|
// 已翻页的数据数目
|
|
|
Long size = 0L;
|
|
|
- int fileIndex = 1;
|
|
|
PrintWriter printWriter = null;
|
|
|
int count = 0;
|
|
|
try {
|
|
|
@@ -416,7 +429,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
printWriter = new PrintWriter(luceneProperties.getComponentsDir() + "/" + fileIndex + ".txt");
|
|
|
while (totalElements > size) {
|
|
|
// 一个文件存放100000条数据,一旦超过,写入新的文件
|
|
|
- if (count > SINGLE_FILE_MAX_SIZE) {
|
|
|
+ if (count == SINGLE_FILE_MAX_SIZE) {
|
|
|
count = 1;
|
|
|
printWriter.flush();
|
|
|
printWriter.close();
|