|
|
@@ -97,15 +97,16 @@ public class IndexServiceImpl implements IndexService {
|
|
|
indexWriter = indexWriterManager.get();
|
|
|
Long startTime = new Date().getTime();
|
|
|
|
|
|
- Long kindSize = createKindIndexs();
|
|
|
+ Long kindSize = createKindIndexes();
|
|
|
Long kindTime = new Date().getTime();
|
|
|
logger.info("创建类目索引: " + kindSize + "条,耗时 " + (kindTime - startTime) + " ms\n");
|
|
|
|
|
|
- Long brandSize = createBrandIndexs();
|
|
|
+ Long brandSize = createBrandIndexes();
|
|
|
Long brandTime = new Date().getTime();
|
|
|
logger.info("创建品牌索引: " + brandSize + "条,耗时 " + (brandTime - kindTime) + " ms\n");
|
|
|
|
|
|
- Long componentSize = createComponentIndexesWithFiles();
|
|
|
+// Long componentSize = createComponentIndexesWithFiles();
|
|
|
+ Long componentSize = createComponentIndexes();
|
|
|
Long componentTime = new Date().getTime();
|
|
|
logger.info("创建器件索引: " + componentSize + "条,耗时 " + (componentTime - brandTime) + " ms\n");
|
|
|
|
|
|
@@ -129,7 +130,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
* @return 写入的类目索引数
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- private Long createKindIndexs() throws IOException {
|
|
|
+ private Long createKindIndexes() throws IOException {
|
|
|
logger.info("正在创建类目索引...");
|
|
|
List<KindSimpleInfo> kinds = kindDao.findAll();
|
|
|
|
|
|
@@ -137,6 +138,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
return 0L;
|
|
|
|
|
|
for (KindSimpleInfo kind : kinds) {
|
|
|
+ logger.info(kind);
|
|
|
Document document = toDocument(kind);
|
|
|
if (document != null)
|
|
|
indexWriter.addDocument(document);
|
|
|
@@ -151,13 +153,14 @@ public class IndexServiceImpl implements IndexService {
|
|
|
* @return 写入的品牌索引数
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- private Long createBrandIndexs() throws IOException {
|
|
|
+ private Long createBrandIndexes() throws IOException {
|
|
|
logger.info("正在创建品牌索引...");
|
|
|
List<BrandSimpleInfo> brands = brandDao.findAll();
|
|
|
if (CollectionUtils.isEmpty(brands))
|
|
|
return 0L;
|
|
|
|
|
|
for (BrandSimpleInfo brand : brands) {
|
|
|
+ logger.info(brand);
|
|
|
Document document = toDocument(brand);
|
|
|
if (document != null) {
|
|
|
indexWriter.addDocument(document);
|
|
|
@@ -167,7 +170,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
return (long) brands.size();
|
|
|
}
|
|
|
|
|
|
- private Long createComponentIndexesWithFiles() {
|
|
|
+ public Long createComponentIndexesWithFiles() {
|
|
|
logger.info("正在创建器件索引...");
|
|
|
Long size = 0L;
|
|
|
try {
|
|
|
@@ -213,7 +216,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
* @return 写入的器件索引数
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public Long createComponentIndexs() throws IOException {
|
|
|
+ public Long createComponentIndexes() throws IOException {
|
|
|
logger.info("正在创建器件索引...");
|
|
|
Long size = 0L;
|
|
|
PageParams params = new PageParams();
|
|
|
@@ -230,6 +233,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
while (totalElements > size) {
|
|
|
List<ComponentSimpleInfo> components = pageResult.getContent();
|
|
|
for (ComponentSimpleInfo component : components) {
|
|
|
+ logger.info(component);
|
|
|
Document document = toDocument(component);
|
|
|
if (document != null) {
|
|
|
indexWriter.addDocument(document);
|
|
|
@@ -263,16 +267,15 @@ public class IndexServiceImpl implements IndexService {
|
|
|
*/
|
|
|
private Document toDocument(KindSimpleInfo kind) {
|
|
|
if (kind == null || kind.getId() == null || StringUtils.isEmpty(kind.getNameCn()) || kind.getIsLeaf() == null
|
|
|
- || kind.getLevel() == null) {
|
|
|
+ || kind.getLevel() == null || StringUtils.isEmpty(kind.getRowid())) {
|
|
|
return null;
|
|
|
}
|
|
|
Document document = new Document();
|
|
|
- // 不能用LongField,否则后续实时更新索引时,方法updateDocument(new Term("", ""),
|
|
|
- // doc)无法根据id进行更新
|
|
|
document.add(new StringField(SearchConstants.KIND_ID_FIELD, String.valueOf(kind.getId()), Store.YES));
|
|
|
document.add(new TextField(SearchConstants.KIND_NAMECN_FIELD, kind.getNameCn(), Store.YES));
|
|
|
document.add(new StringField(SearchConstants.KIND_ISLEAF_FIELD, String.valueOf(kind.getIsLeaf()), Store.YES));
|
|
|
document.add(new StringField(SearchConstants.KIND_LEVEL_FIELD, String.valueOf(kind.getLevel()), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.KIND_ROWID_FIELD, kind.getRowid(), Store.YES));
|
|
|
return document;
|
|
|
}
|
|
|
|
|
|
@@ -284,20 +287,18 @@ public class IndexServiceImpl implements IndexService {
|
|
|
*/
|
|
|
private Document toDocument(BrandSimpleInfo brand) {
|
|
|
if (brand == null || brand.getId() == null || StringUtils.isEmpty(brand.getNameCn())
|
|
|
- || StringUtils.isEmpty(brand.getUuid())) {
|
|
|
+ || StringUtils.isEmpty(brand.getUuid()) || StringUtils.isEmpty(brand.getRowid())) {
|
|
|
return null;
|
|
|
}
|
|
|
Document document = new Document();
|
|
|
document.add(new StringField(SearchConstants.BRAND_ID_FIELD, String.valueOf(brand.getId()), Store.YES));
|
|
|
- String nameCn = brand.getNameCn();
|
|
|
- if (!StringUtils.isEmpty(nameCn)) {
|
|
|
- document.add(new TextField(SearchConstants.BRAND_NAMECN_FIELD, nameCn, Store.YES));
|
|
|
- }
|
|
|
+ document.add(new TextField(SearchConstants.BRAND_NAMECN_FIELD, brand.getNameCn(), Store.YES));
|
|
|
String nameEn = brand.getNameEn();
|
|
|
if (!StringUtils.isEmpty(nameEn)) {
|
|
|
document.add(new TextField(SearchConstants.BRAND_NAMEEN_FIELD, nameEn, Store.YES));
|
|
|
}
|
|
|
document.add(new StringField(SearchConstants.BRAND_UUID_FIELD, brand.getUuid(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.BRAND_ROWID_FIELD, brand.getRowid(), Store.YES));
|
|
|
return document;
|
|
|
}
|
|
|
|
|
|
@@ -310,7 +311,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
private Document toDocument(ComponentSimpleInfo component) {
|
|
|
if (component == null || component.getId() == null || StringUtils.isEmpty(component.getUuid())
|
|
|
|| StringUtils.isEmpty(component.getCode()) || component.getKindid() == null
|
|
|
- || component.getBrandid() == null) {
|
|
|
+ || component.getBrandid() == null || StringUtils.isEmpty(component.getRowid())) {
|
|
|
return null;
|
|
|
}
|
|
|
Document document = new Document();
|
|
|
@@ -323,6 +324,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
Store.YES));
|
|
|
document.add(new StringField(SearchConstants.COMPONENT_BRANDID_FIELD, String.valueOf(component.getBrandid()),
|
|
|
Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.COMPONENT_ROWID_FIELD, component.getRowid(), Store.YES));
|
|
|
|
|
|
// 属性值加入索引,索引中field的键:"pr_"前缀连接属性的id
|
|
|
Set<PropertyValue> propertyValues = component.getProperties();
|
|
|
@@ -411,22 +413,20 @@ public class IndexServiceImpl implements IndexService {
|
|
|
KindSimpleInfo kind = (KindSimpleInfo) obj;
|
|
|
Document document = toDocument(kind);
|
|
|
if (document != null) {
|
|
|
- indexWriter.updateDocument(new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(kind.getId())),
|
|
|
- document);
|
|
|
+ indexWriter.updateDocument(new Term(SearchConstants.KIND_ROWID_FIELD, kind.getRowid()), document);
|
|
|
}
|
|
|
} else if (obj instanceof BrandSimpleInfo) {
|
|
|
BrandSimpleInfo brand = (BrandSimpleInfo) obj;
|
|
|
Document document = toDocument((BrandSimpleInfo) obj);
|
|
|
if (document != null) {
|
|
|
- indexWriter.updateDocument(new Term(SearchConstants.BRAND_ID_FIELD, String.valueOf(brand.getId())),
|
|
|
- document);
|
|
|
+ indexWriter.updateDocument(new Term(SearchConstants.BRAND_ROWID_FIELD, brand.getRowid()), document);
|
|
|
}
|
|
|
} else if (obj instanceof ComponentSimpleInfo) {
|
|
|
ComponentSimpleInfo component = (ComponentSimpleInfo) obj;
|
|
|
Document document = toDocument(component);
|
|
|
if (document != null) {
|
|
|
- indexWriter.updateDocument(
|
|
|
- new Term(SearchConstants.COMPONENT_ID_FIELD, String.valueOf(component.getId())), document);
|
|
|
+ indexWriter.updateDocument(new Term(SearchConstants.COMPONENT_ROWID_FIELD, component.getRowid()),
|
|
|
+ document);
|
|
|
}
|
|
|
} else {
|
|
|
logger.error("message parsing failed!");
|
|
|
@@ -450,14 +450,14 @@ public class IndexServiceImpl implements IndexService {
|
|
|
try {
|
|
|
indexWriter = indexWriterManager.get();
|
|
|
if (obj instanceof KindSimpleInfo) {
|
|
|
- indexWriter.deleteDocuments(
|
|
|
- new Term(SearchConstants.KIND_ID_FIELD, ((KindSimpleInfo) obj).getId().toString()));
|
|
|
+ indexWriter
|
|
|
+ .deleteDocuments(new Term(SearchConstants.KIND_ROWID_FIELD, ((KindSimpleInfo) obj).getRowid()));
|
|
|
} else if (obj instanceof BrandSimpleInfo) {
|
|
|
indexWriter.deleteDocuments(
|
|
|
- new Term(SearchConstants.BRAND_ID_FIELD, ((BrandSimpleInfo) obj).getId().toString()));
|
|
|
+ new Term(SearchConstants.BRAND_ROWID_FIELD, ((BrandSimpleInfo) obj).getRowid()));
|
|
|
} else if (obj instanceof ComponentSimpleInfo) {
|
|
|
indexWriter.deleteDocuments(
|
|
|
- new Term(SearchConstants.COMPONENT_ID_FIELD, ((ComponentSimpleInfo) obj).getId().toString()));
|
|
|
+ new Term(SearchConstants.COMPONENT_ROWID_FIELD, ((ComponentSimpleInfo) obj).getRowid()));
|
|
|
} else {
|
|
|
logger.error("message parsing failed!");
|
|
|
}
|