Browse Source

bugfix-更新文章索引

Aslee 2 years ago
parent
commit
64f77d3117

+ 9 - 5
src/main/java/com/caimei365/commodity/service/impl/SearchIndexServiceImpl.java

@@ -185,7 +185,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 获取推送记录数
         Integer articleRecord = setAllArticleData(mainId, articleCount, false);
         if (articleCount > articleRecord) {
-            log.warn("批量添加文章文档异常,部分文章未添加。");
+            log.warn("批量添加文章文档异常,部分文章未添加。应加数量:" + articleCount + ",实加数量:" + articleRecord);
         }
         return ResponseJson.success(articleRecord);
     }
@@ -1003,10 +1003,11 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * @return int
      */
     private Integer setAllArticleData(Integer mainId, Integer articleCount, boolean initFlag) {
-        // 批量推送,每100条推送一次
-        int loop = (int) Math.ceil(articleCount.doubleValue() / 100);
+        // 批量推送,每50条推送一次
+        int loop = (int) Math.ceil(articleCount.doubleValue() / 50);
         Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
         if (!initFlag) {
+            // 获取阿里云已存在的文章文档id
             Integer record = searchQueryService.getRecordByDocType("article");
             int l = (int) Math.ceil(record.doubleValue() / 500);
             for (int i = 1; i <= l; i++) {
@@ -1017,7 +1018,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 定义返回结果
         int articleRecord = 0;
         for (int i = 1; i <= loop; i++) {
-            PageHelper.startPage(i, 100);
+            PageHelper.startPage(i, 50);
             // 获取数据库文章列表的分页数据
             List<ArticleDO> dbList = searchMapper.searchArticleList();
             // 定义文章文档数据
@@ -1054,7 +1055,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 pushArticleDocument(mainList, articleList);
                 // 添加到返回结果
                 articleRecord += mainList.size();
-            } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
+                log.info("批量更新第" + i + "页文章文档,数据库条数:" + dbList.size() + ",本次更新条数:" + mainList.size() + ",总更新条数:" + articleRecord);
+                // 降低推送频率,防止触发推送频率限制导致推送失败
+                Thread.sleep(1000);
+            } catch (OpenSearchClientException | OpenSearchException | JSONException | InterruptedException e) {
                 log.error("批量添加文章文档异常:" + e);
                 articleRecord += 0;
             }

+ 1 - 1
src/main/resources/mapper/SearchMapper.xml

@@ -251,7 +251,7 @@
         from info as a
         <include refid="Article_Joins"/>
         where a.enabledStatus = 1 and a.auditStatus = 2 and a.onlineStatus = 2
-        order by a.priorityIndex desc
+        order by a.id desc
     </select>
     <select id="searchArticleById" resultType="com.caimei365.commodity.model.search.ArticleDO">
         select