|
|
@@ -6,6 +6,7 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.FileReader;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -17,7 +18,6 @@ import org.apache.lucene.store.FSDirectory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -213,20 +213,8 @@ public class IndexServiceImpl implements IndexService {
|
|
|
private Long createKindIndexs() throws IOException {
|
|
|
logger.info("正在创建类目索引...");
|
|
|
List<KindSimpleInfo> kinds = kindDao.findAll();
|
|
|
- if (CollectionUtils.isEmpty(kinds)) {
|
|
|
- return 0L;
|
|
|
- }
|
|
|
logger.info("发现数据:" + kinds.size() + "条");
|
|
|
- long count = 0;
|
|
|
- for (KindSimpleInfo kind : kinds) {
|
|
|
- Document document = ObjectToDocumentUtils.toDocument(kind);
|
|
|
- if (document != null) {
|
|
|
- indexWriter.addDocument(document);
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- indexWriter.commit();
|
|
|
- return count;
|
|
|
+ return createIndexesWithObjects(kinds.toArray());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -238,20 +226,8 @@ public class IndexServiceImpl implements IndexService {
|
|
|
private Long createBrandIndexs() throws IOException {
|
|
|
logger.info("正在创建品牌索引...");
|
|
|
List<BrandSimpleInfo> brands = brandDao.findAll();
|
|
|
- if (CollectionUtils.isEmpty(brands)) {
|
|
|
- return 0L;
|
|
|
- }
|
|
|
logger.info("发现数据:" + brands.size() + "条");
|
|
|
- long count = 0;
|
|
|
- for (BrandSimpleInfo brand : brands) {
|
|
|
- Document document = ObjectToDocumentUtils.toDocument(brand);
|
|
|
- if (document != null) {
|
|
|
- indexWriter.addDocument(document);
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- indexWriter.commit();
|
|
|
- return count;
|
|
|
+ return createIndexesWithObjects(brands.toArray());
|
|
|
}
|
|
|
|
|
|
private Long createComponentIndexesWithFiles() {
|
|
|
@@ -552,27 +528,28 @@ public class IndexServiceImpl implements IndexService {
|
|
|
}
|
|
|
|
|
|
String[] strs = ids.split(",");
|
|
|
- Long[] longIds = new Long[strs.length];
|
|
|
- for (int i = 0; i < strs.length; i++) {
|
|
|
- longIds[i] = Long.parseLong(strs[i]);
|
|
|
+ List<Long> idList = new ArrayList<>();
|
|
|
+ for (String str : strs) {
|
|
|
+ idList.add(Long.parseLong(str));
|
|
|
}
|
|
|
if (tableName.equals(SearchConstants.KIND_TABLE_NAME)) {
|
|
|
- List<KindSimpleInfo> kinds = kindDao.findByIds(longIds);
|
|
|
+ List<KindSimpleInfo> kinds = kindDao.findAll(idList);
|
|
|
for (KindSimpleInfo kind : kinds) {
|
|
|
update(kind);
|
|
|
}
|
|
|
} else if (tableName.equals(SearchConstants.BRAND_TABLE_NAME)) {
|
|
|
- List<BrandSimpleInfo> brands = brandDao.findByIds(longIds);
|
|
|
+ List<BrandSimpleInfo> brands = brandDao.findAll(idList);
|
|
|
for (BrandSimpleInfo brand : brands) {
|
|
|
update(brand);
|
|
|
}
|
|
|
} else if (tableName.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
|
|
|
- List<ComponentSimpleInfo> components = componentDao.findByIds(longIds);
|
|
|
+ List<ComponentSimpleInfo> components = componentDao.findAll(idList);
|
|
|
for (ComponentSimpleInfo component : components) {
|
|
|
update(component);
|
|
|
}
|
|
|
} else {
|
|
|
- throw new SearchException("需指定要维护的ids,多个id以英文逗号隔开,如:321,988");
|
|
|
+ throw new SearchException("需指定要维护的表名:" + SearchConstants.KIND_TABLE_NAME + "、"
|
|
|
+ + SearchConstants.BRAND_TABLE_NAME + "、" + SearchConstants.COMPONENT_TABLE_NAME);
|
|
|
}
|
|
|
return "维护成功";
|
|
|
}
|