|
@@ -193,16 +193,20 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<Integer> updateProductIndexById(Integer productId){
|
|
|
+ if (null == productId) {
|
|
|
+ log.info(">>>更新商品,商品Id不能为空!");
|
|
|
+ return ResponseJson.error("商品Id不能为空", null);
|
|
|
+ }
|
|
|
ProductDO product = searchMapper.searchProductById(productId);
|
|
|
if (null != product) {
|
|
|
// 定义星范商品数据
|
|
|
List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
- // 星范商品设值,【必须先于商品文档设值】
|
|
|
- Integer mallId = setMallProductDocument(mallProductList, productId);
|
|
|
+// // 星范商品设值,【必须先于商品文档设值】
|
|
|
+// Integer mallId = setMallProductDocument(mallProductList, productId);
|
|
|
// 定义商品文档数据
|
|
|
List<DocumentDTO<ProductDO>> productList = new ArrayList<>();
|
|
|
// 商品文档设值
|
|
|
- setProductDocument(productList, product, mallId);
|
|
|
+ setProductDocument(productList, product, null);
|
|
|
// 定义主文档入口数据
|
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
|
// 主文档设值
|
|
@@ -210,14 +214,23 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ // 新增主文档, 商品:type=1
|
|
|
+ setMainDocument(1, mainList, mainId, productId);
|
|
|
}
|
|
|
- // 商品文档 type=1
|
|
|
- setMainDocument(1, mainList, mainId, productId);
|
|
|
try {
|
|
|
- // 推送到阿里云
|
|
|
- pushProductDocument(mainList, productList, mallProductList);
|
|
|
- // 返回结果
|
|
|
- return ResponseJson.success(mainList.size());
|
|
|
+ // 查询商品数量是否唯一,不唯一则删除后更新索引
|
|
|
+ Integer count = searchQueryService.getCountByDocId("product", productId);
|
|
|
+ if (count > 1) {
|
|
|
+ log.info("商品重复,重复商品>>>>>>>>>>>" + productId +"重复数量:" + count);
|
|
|
+ // 删除主文档记录
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
+ return updateProductIndexById(productId);
|
|
|
+ } else {
|
|
|
+ // 推送到阿里云
|
|
|
+ pushProductDocument(mainList, productList, mallProductList);
|
|
|
+ // 返回结果
|
|
|
+ return ResponseJson.success(mainList.size());
|
|
|
+ }
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
|
log.error("添加商品文档异常:" + e);
|
|
|
return ResponseJson.error("添加商品文档异常", null);
|
|
@@ -235,6 +248,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<Integer> updateSupplierIndexById(Integer shopId) {
|
|
|
+ if (null == shopId) {
|
|
|
+ log.info(">>>更新供应商,供应商Id不能为空!");
|
|
|
+ return ResponseJson.error("供应商Id不能为空", null);
|
|
|
+ }
|
|
|
SupplierDO supplier = searchMapper.searchSupplierById(shopId);
|
|
|
if(null != supplier){
|
|
|
// 定义供应商文档数据
|
|
@@ -248,14 +265,23 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ // 新增主文档, 供应商:type=2
|
|
|
+ setMainDocument(2, mainList, mainId, shopId);
|
|
|
}
|
|
|
- // 供应商文档 type=2
|
|
|
- setMainDocument(2, mainList, mainId, shopId);
|
|
|
try {
|
|
|
- // 将文档列表转换成Json串,并推送到阿里云
|
|
|
- pushSupplierDocument(mainList, supplierList);
|
|
|
- // 返回结果
|
|
|
- return ResponseJson.success(mainList.size());
|
|
|
+ // 查询供应商是否唯一,不唯一则删除后重新更新索引
|
|
|
+ Integer count = searchQueryService.getCountByDocId("shop", shopId);
|
|
|
+ if (count > 1) {
|
|
|
+ log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId +"重复数量:" + count);;
|
|
|
+ // 删除主文档记录
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
+ return updateSupplierIndexById(shopId);
|
|
|
+ } else {
|
|
|
+ // 将文档列表转换成Json串,并推送到阿里云
|
|
|
+ pushSupplierDocument(mainList, supplierList);
|
|
|
+ // 返回结果
|
|
|
+ return ResponseJson.success(mainList.size());
|
|
|
+ }
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
|
log.error("添加供应商文档异常:" + e);
|
|
|
return ResponseJson.error("添加供应商文档异常", null);
|
|
@@ -273,6 +299,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<Integer> updateEquipmentIndexById(Integer equipmentId) {
|
|
|
+ if (null == equipmentId) {
|
|
|
+ log.info(">>>更新项目仪器,项目仪器Id不能为空!");
|
|
|
+ return ResponseJson.error("项目仪器Id不能为空", null);
|
|
|
+ }
|
|
|
EquipmentDO equipment = searchMapper.searchEquipmentById(equipmentId);
|
|
|
if(null != equipment){
|
|
|
// 定义项目仪器文档数据
|
|
@@ -286,14 +316,23 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ // 新增主文档, 项目仪器:type=3
|
|
|
+ setMainDocument(3, mainList, mainId, equipmentId);
|
|
|
}
|
|
|
- // 项目仪器文档 type=3
|
|
|
- setMainDocument(3, mainList, mainId, equipmentId);
|
|
|
try {
|
|
|
- // 将文档列表转换成Json串,并推送到阿里云
|
|
|
- pushEquipmentDocument(mainList, equipmentList);
|
|
|
- // 返回结果
|
|
|
- return ResponseJson.success(mainList.size());
|
|
|
+ // 查询项目仪器数量是否唯一,不唯一则删除后重新更新索引
|
|
|
+ Integer count = searchQueryService.getCountByDocId("equipment", equipmentId);
|
|
|
+ if (count > 1) {
|
|
|
+ log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId+"重复数量:" + count);
|
|
|
+ // 删除主文档记录
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
+ return updateEquipmentIndexById(equipmentId);
|
|
|
+ } else {
|
|
|
+ // 将文档列表转换成Json串,并推送到阿里云
|
|
|
+ pushEquipmentDocument(mainList, equipmentList);
|
|
|
+ // 返回结果
|
|
|
+ return ResponseJson.success(mainList.size());
|
|
|
+ }
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
|
log.error("添加项目仪器文档异常:" + e);
|
|
|
return ResponseJson.error("添加项目仪器文档异常", null);
|
|
@@ -311,6 +350,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<Integer> updateArticleIndexById(Integer articleId) {
|
|
|
+ if (null == articleId) {
|
|
|
+ log.info(">>>更新文章,文章Id不能为空!");
|
|
|
+ return ResponseJson.error("文章Id不能为空", null);
|
|
|
+ }
|
|
|
ArticleDO article = searchMapper.searchArticleById(articleId);
|
|
|
if(null != article){
|
|
|
// 定义文章文档数据
|
|
@@ -324,21 +367,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ // 新增主文档, 文章 type=4
|
|
|
+ setMainDocument(4, mainList, mainId, articleId);
|
|
|
}
|
|
|
- // 文章文档 type=4
|
|
|
- setMainDocument(4, mainList, mainId, articleId);
|
|
|
+
|
|
|
try {
|
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
- pushArticleDocument(mainList, articleList);
|
|
|
// 查询文章数量是否唯一,不唯一则删除后重新更新索引
|
|
|
Integer count = searchQueryService.getCountByDocId("article", articleId);
|
|
|
if (count > 1) {
|
|
|
- log.info("文章重复,重复文章id>>>>>>>>>>>" + articleId);
|
|
|
- deleteArticleIndexById(articleId);
|
|
|
- updateArticleIndexById(articleId);
|
|
|
+ log.info("文章重复,重复文章>>>>>>>>>>>" + articleId +"重复数量:" + count);
|
|
|
+ // 删除主文档记录
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
+ return updateArticleIndexById(articleId);
|
|
|
+ } else {
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
+ pushArticleDocument(mainList, articleList);
|
|
|
+ // 返回结果
|
|
|
+ return ResponseJson.success(articleList.size());
|
|
|
}
|
|
|
- // 返回结果
|
|
|
- return ResponseJson.success(mainList.size());
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
|
log.error("添加文章文档异常:" + e);
|
|
|
return ResponseJson.error("添加文章文档异常", null);
|
|
@@ -364,6 +410,9 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
deleteDocByTypeId("m_id", mallId, "search_product_mall");
|
|
|
}
|
|
|
deleteDocByTypeId("p_id", productId, "search_product");
|
|
|
+ // 删除主文档记录
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("product", productId);
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
// 返回结果
|
|
|
return ResponseJson.success(1);
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
@@ -382,6 +431,9 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
public ResponseJson<Integer> deleteSupplierIndexById(Integer shopId) {
|
|
|
try {
|
|
|
deleteDocByTypeId("s_id", shopId, "search_supplier");
|
|
|
+ // 删除主文档记录
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("shop", shopId);
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
// 返回结果
|
|
|
return ResponseJson.success(1);
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
@@ -400,6 +452,9 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
public ResponseJson<Integer> deleteEquipmentIndexById(Integer equipmentId) {
|
|
|
try {
|
|
|
deleteDocByTypeId("e_id", equipmentId, "search_equipment");
|
|
|
+ // 删除主文档记录
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("equipment", equipmentId);
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
// 返回结果
|
|
|
return ResponseJson.success(1);
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
@@ -417,7 +472,11 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
@Override
|
|
|
public ResponseJson<Integer> deleteArticleIndexById(Integer articleId) {
|
|
|
try {
|
|
|
+ // 删除文章文档记录
|
|
|
deleteDocByTypeId("a_id", articleId, "search_article");
|
|
|
+ // 删除主文档记录
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("article", articleId);
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
// 返回结果
|
|
|
return ResponseJson.success(1);
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
@@ -488,9 +547,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
deleteDoc.put("m_id", mallId);
|
|
|
}
|
|
|
}
|
|
|
- for (Integer productId : invalidIds) {
|
|
|
+ for (Integer invalidId : invalidIds) {
|
|
|
// 根据ID(主键)删除文档
|
|
|
- deleteDoc.put("p_id", productId);
|
|
|
+ deleteDoc.put("p_id", invalidId);
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("product", invalidId);
|
|
|
+ if (mainId > -1){
|
|
|
+ deleteDoc.put("id", mainId);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
String deleteJsonStr = setDeleteDocument(deleteDoc);
|
|
@@ -537,10 +600,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
int productMainId;
|
|
|
for (ProductDO product : dbList) {
|
|
|
- // 星范商品设值,【必须先于商品文档设值】
|
|
|
- Integer mallId = setMallProductDocument(mallProductList, product.getP_id());
|
|
|
+// // 星范商品设值,【必须先于商品文档设值】
|
|
|
+// Integer mallId = setMallProductDocument(mallProductList, product.getP_id());
|
|
|
// 商品文档设值
|
|
|
- setProductDocument(productList, product, mallId);
|
|
|
+ setProductDocument(productList, product, null);
|
|
|
// 主文档设值
|
|
|
Integer productId = product.getP_id();
|
|
|
if(initFlag){
|
|
@@ -583,14 +646,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushProductDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ProductDO>> productList, List<DocumentDTO<MallProductDO>> mallProductList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
+ }
|
|
|
// 将商品文档推送到阿里云
|
|
|
String productDocStr = new JSONArray(productList).toString();
|
|
|
String productResult = searchOpenService.pushDocument(productDocStr, "search_product");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "):" + productResult + "】");
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 新增
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
+ } else {
|
|
|
+ // 更新
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
+ }
|
|
|
// 将星范商品推送到阿里云
|
|
|
if (mallProductList.size()>0) {
|
|
|
String mallProductStr = new JSONArray(mallProductList).toString();
|
|
@@ -613,9 +684,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<Integer> invalidIds = searchMapper.findSupplierInvalidIds();
|
|
|
// 删除文档只需要设置需删除文档主键值即可
|
|
|
Map<String, Object> deleteDoc = Maps.newLinkedHashMap();
|
|
|
- for (Integer productId : invalidIds) {
|
|
|
+ for (Integer invalidId : invalidIds) {
|
|
|
// 根据ID(主键)删除文档
|
|
|
- deleteDoc.put("s_id", productId);
|
|
|
+ deleteDoc.put("s_id", invalidId);
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("shop", invalidId);
|
|
|
+ if (mainId > -1){
|
|
|
+ deleteDoc.put("id", mainId);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
String deleteJsonStr = setDeleteDocument(deleteDoc);
|
|
@@ -703,14 +778,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushSupplierDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<SupplierDO>> supplierList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
+ }
|
|
|
// 将商品文档推送到阿里云
|
|
|
String supplierDocStr = new JSONArray(supplierList).toString();
|
|
|
String supplierResult = searchOpenService.pushDocument(supplierDocStr, "search_supplier");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "):" + supplierResult + "】");
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 新增
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
|
|
|
+ } else {
|
|
|
+ // 更新
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -727,9 +810,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<Integer> invalidIds = searchMapper.findEquipmentInvalidIds();
|
|
|
// 删除文档只需要设置需删除文档主键值即可
|
|
|
Map<String, Object> deleteDoc = Maps.newLinkedHashMap();
|
|
|
- for (Integer productId : invalidIds) {
|
|
|
+ for (Integer invalidId : invalidIds) {
|
|
|
// 根据ID(主键)删除文档
|
|
|
- deleteDoc.put("e_id", productId);
|
|
|
+ deleteDoc.put("e_id", invalidId);
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("equipment", invalidId);
|
|
|
+ if (mainId > -1){
|
|
|
+ deleteDoc.put("id", mainId);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
String deleteJsonStr = setDeleteDocument(deleteDoc);
|
|
@@ -817,14 +904,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushEquipmentDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<EquipmentDO>> equipmentList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
+ }
|
|
|
// 将商品文档推送到阿里云
|
|
|
String equipmentDocStr = new JSONArray(equipmentList).toString();
|
|
|
String equipmentResult = searchOpenService.pushDocument(equipmentDocStr, "search_equipment");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "):" + equipmentResult + "】");
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 新增
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
|
|
|
+ } else {
|
|
|
+ // 更新
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -841,9 +936,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<Integer> invalidIds = searchMapper.findArticleInvalidIds();
|
|
|
// 删除文档只需要设置需删除文档主键值即可
|
|
|
Map<String, Object> deleteDoc = Maps.newLinkedHashMap();
|
|
|
- for (Integer productId : invalidIds) {
|
|
|
+ for (Integer invalidId : invalidIds) {
|
|
|
// 根据ID(主键)删除文档
|
|
|
- deleteDoc.put("a_id", productId);
|
|
|
+ deleteDoc.put("a_id", invalidId);
|
|
|
+ Integer mainId = searchQueryService.getIdByDocId("article", invalidId);
|
|
|
+ if (mainId > -1){
|
|
|
+ deleteDoc.put("id", mainId);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
String deleteJsonStr = setDeleteDocument(deleteDoc);
|
|
@@ -931,14 +1030,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushArticleDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ArticleDO>> articleList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
+ }
|
|
|
// 将商品文档推送到阿里云
|
|
|
String articleDocStr = new JSONArray(articleList).toString();
|
|
|
String articleResult = searchOpenService.pushDocument(articleDocStr, "search_article");
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "):" + articleResult + "】");
|
|
|
+ if (mainList.size()>0) {
|
|
|
+ // 新增
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
|
|
|
+ } else {
|
|
|
+ // 更新
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|