Kaynağa Gözat

搜索文章

chao 4 yıl önce
ebeveyn
işleme
32675b7331

+ 82 - 2
src/main/java/com/caimei365/commodity/components/SearchOpenService.java

@@ -5,7 +5,6 @@ import com.aliyun.opensearch.OpenSearchClient;
 import com.aliyun.opensearch.SearcherClient;
 import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONArray;
-import com.aliyun.opensearch.sdk.dependencies.org.json.JSONException;
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONObject;
 import com.aliyun.opensearch.sdk.generated.OpenSearch;
 import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
@@ -14,7 +13,6 @@ import com.aliyun.opensearch.sdk.generated.commons.OpenSearchResult;
 import com.aliyun.opensearch.sdk.generated.search.*;
 import com.aliyun.opensearch.sdk.generated.search.general.SearchResult;
 import com.aliyun.opensearch.search.SearchResultDebug;
-import com.caimei365.commodity.model.ResponseJson;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -373,4 +371,86 @@ public class SearchOpenService {
         return searchParams;
     }
 
+    /**
+     * 滚动查询
+     *
+     * @param searchParams  查询参数对象
+     * @param queryStr 查询类型及参数串
+     * @param pageNum       页码
+     * @param pageSize      每页数量
+     * @param requestPageSize  每次scroll数量
+     * @return list
+     */
+    public JSONObject deepPagingForParams(SearchParams searchParams, String queryStr, int maxSearchNum, int requestPageSize, int pageNum, int pageSize) throws OpenSearchClientException, OpenSearchException {
+        //设置scroll方式查询
+        DeepPaging deep =new DeepPaging();
+        //不设置默认为1m表示1分钟,该参数表示本次返回的scrollid的有效期
+        deep.setScrollExpire("3m");
+        //添加DeepPaging对象参数
+        searchParams.setDeepPaging(deep);
+        // 查询推送
+        JSONObject pageObj = new JSONObject();
+        JSONObject result = getResultJsonObject(queryStr, searchParams);
+        int status = result.getInt("status");
+        pageObj.put("status", status);
+        if (1 == status) {
+            int requestSize = pageNum*pageSize;
+            int total = result.getInt("total");
+            int totalPage = (int) Math.ceil( (double)total/pageSize);
+            JSONArray pageData = new JSONArray();
+            int loop = (int)Math.ceil((double) requestSize / requestPageSize);
+            for (int l=1; l<=loop; l++) {
+                //第一次执行不返回数据,主要返回scroll_id值,第二次调用查询时设置scroll_id
+                deep.setScrollId(result.getString("scroll_id"));
+                //不设置默认为1m表示1分钟,如不想使用默认值,每次重新调用前必须要重新设置下
+                deep.setScrollExpire("3m");
+                // 查询推送
+                result = getResultJsonObject(queryStr, searchParams);
+                if (1 == status) {
+                    JSONArray resultArr = result.getJSONArray("items");
+                    if (resultArr.length()>0){
+                        if (requestSize > maxSearchNum){
+                            if (l==loop) {
+                                int baseSize = Math.min(requestSize - (requestPageSize*(loop-1)), resultArr.length());
+                                // 上一页数量往前总数量 - 上一轮循环后总数量 = 当前循环的上一页之前数量
+                                int baseNum = pageSize*(pageNum-1) - requestPageSize*(loop-1);
+                                for (int i=0; i<pageSize; i++) {
+                                    int index = baseNum + i;
+                                    if (index<baseSize){
+                                        JSONObject item = resultArr.getJSONObject(index);
+                                        pageData.put(i, item);
+                                    } else {
+                                        break;
+                                    }
+                                }
+                            }
+                        } else {
+                            int baseNum = (pageNum-1)*pageSize;
+                            int currentTotal = requestSize;
+                            if (totalPage == pageNum){
+                                currentTotal = total;
+                            }
+                            for (int i=0; i<pageSize; i++) {
+                                int index = baseNum + i;
+                                if (index<currentTotal){
+                                    JSONObject item = resultArr.getJSONObject(index);
+                                    pageData.put(i, item);
+                                } else {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            pageObj.put("total", total);
+            pageObj.put("items", pageData);
+            log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
+        }
+        return pageObj;
+    }
+
+
+
+
 }

+ 1 - 1
src/main/java/com/caimei365/commodity/controller/SearchProductApi.java

@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author : Charles
  * @date : 2021/4/7
  */
-@Api(tags="搜索查询API")
+@Api(tags="搜索商品API")
 @RestController
 @RequiredArgsConstructor
 @RequestMapping("/commodity/search/query")

+ 82 - 4
src/main/java/com/caimei365/commodity/controller/SearchQueryApi.java

@@ -26,12 +26,12 @@ public class SearchQueryApi {
     private final SearchQueryService searchQueryService;
 
     /**
-     * 根据文档Id获取索引Id
+     * 根据文档Id获取阿里云索引Id
      *
      * spi旧接口:/search/query/(id,pid,sid,eid,aid)
      * @return int
      */
-    @ApiOperation("根据文档Id获取索引Id")
+    @ApiOperation("根据文档Id获取阿里云索引Id")
     @ApiImplicitParams({
         @ApiImplicitParam(required = false, name = "docType", value = "文档类型(product,shop,equipment,article)"),
         @ApiImplicitParam(required = false, name = "docId", value = "文档Id")
@@ -42,12 +42,12 @@ public class SearchQueryApi {
     }
 
     /**
-     * 根据文档类型获取索引Id集合
+     * 根据文档类型获取阿里云索引Id集合
      *
      * spi旧接口:/search/query/(product,supplier,equipment,article)/ids
      * @return map
      */
-    @ApiOperation("根据文档类型获取索引Id集合")
+    @ApiOperation("根据文档类型获取阿里云索引Id集合")
     @ApiImplicitParams({
         @ApiImplicitParam(required = true, name = "docType", value = "文档类型(product,shop,equipment,article)"),
         @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
@@ -130,4 +130,82 @@ public class SearchQueryApi {
                                              @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
         return searchQueryService.queryEquipmentByKeyword(keyword, pageNum, pageSize);
     }
+
+    /**
+     * 根据关键词搜索文章
+     *
+     * spi旧接口:/search/query/article
+     *
+     * @param keyword 搜索关键字
+     */
+    @ApiOperation("根据关键词搜索文章")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("article")
+    public ResponseJson<String> queryArticleByKeyword(String keyword,
+                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                           @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return searchQueryService.queryArticleByKeyword(keyword, pageNum, pageSize);
+    }
+
+    /**
+     * 根据文章ID搜索文章
+     *
+     * spi旧接口:/search/query/article/{id}
+     *
+     * @param id 文章id
+     */
+    @ApiOperation("根据文章ID搜索文章")
+    @GetMapping("article/{id}")
+    public ResponseJson<String> queryArticleByArticleId(@PathVariable("id") Integer id) {
+        return searchQueryService.queryArticleByArticleId(id);
+    }
+
+    /**
+     * 根据分类搜索文章
+     *
+     * spi旧接口:/search/query/article/type
+     *
+     * @param id 分类id
+     * @return list
+     */
+    @ApiOperation("根据分类搜索文章")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = false, name = "id", value = "分类id"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("article/type")
+    public ResponseJson<String> queryArticleByType(Integer id,
+                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                        @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return searchQueryService.queryArticleByType(id, pageNum, pageSize);
+    }
+
+    /**
+     * 根据标签搜索文章
+     *
+     * spi旧接口:/search/query/article/label
+     *
+     * @param id 标签id
+     * @return list
+     */
+    @ApiOperation("根据标签搜索文章")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = false, name = "id", value = "标签id"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("article/label")
+    public ResponseJson<String> queryArticleByLabel(Integer id,
+                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                         @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return searchQueryService.queryArticleByLabel(id, pageNum, pageSize);
+    }
+
+
+
 }

+ 13 - 41
src/main/java/com/caimei365/commodity/mapper/SearchMapper.java

@@ -1,6 +1,8 @@
 package com.caimei365.commodity.mapper;
 
 import com.caimei365.commodity.model.search.*;
+import com.caimei365.commodity.model.vo.ArticleListVo;
+import com.caimei365.commodity.model.vo.EquipmentListVo;
 import com.caimei365.commodity.model.vo.ProductListVo;
 import com.caimei365.commodity.model.vo.ShopListVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -88,6 +90,10 @@ public interface SearchMapper {
      * 根据文章标签查找标签Id
      */
     List<Integer> findLabelIdsByName(@Param("labelTexts") String[] labelTexts);
+    /**
+     * 根据文章Id查找标签文本
+     */
+    String findLabelNameById(@Param("labelId") Integer labelId);
     /**
      * 获取所有失效商品数量
      */
@@ -155,52 +161,18 @@ public interface SearchMapper {
      * @param keyword   关键词
      * @return list
      */
-    List<ShopListVo> querySupplier(@Param("keyword")  String keyword);
-
-
-
-
-
-
-
-
-
-
-
-
-
-    /**
-     * 根据关键词获取数据库供应商
-     * @param keyword
-     * @return
-     */
-    List<SupplierDO> searchDbSupplierByKeyword(String keyword);
-
-    /**
-     * 根据关键词获取数据库项目仪器
-     * @param keyword
-     * @return
-     */
-    List<EquipmentDO> searchDbEquipmentByKeyword(String keyword);
-
+    List<ShopListVo> querySupplier(@Param("keyword") String keyword);
     /**
-     * 获取数据库商品
-     * @param shopID    供应商id
+     * 获取数据库项目仪器
      * @param keyword   关键词
-     * @param typeId    分类id
-     * @param idType    分类类型(1一级分类,2二级分类,3三级分类)
-     * @param identity  用户身份
-     * @param sortField 排序类型
-     * @param sortType  排序顺序
-     * @return
+     * @return list
      */
-    List<ProductDO> searchDbProduct(@Param("shopID") Integer shopID, @Param("keyword") String keyword, @Param("typeId") Integer typeId, @Param("idType") Integer idType, @Param("identity") Integer identity, @Param("sortField") String sortField, @Param("sortType") Integer sortType);
-
+    List<EquipmentListVo> queryEquipment(@Param("keyword") String keyword);
     /**
      * 获取数据库文章
-     * @return
+     * @param keyword   关键词
+     * @return list
      */
-    List<DbArticleDO> searchDbArticle(@Param("articleId") Integer id, @Param("keyword") String keyword, @Param("typeId") Integer typeId, @Param("labelId") Integer labelId);
-
+    List<ArticleListVo> queryArticle(@Param("keyword") String keyword, @Param("articleId") Integer articleId, @Param("typeId") Integer typeId, @Param("labelText") String labelText);
 
 }

+ 43 - 0
src/main/java/com/caimei365/commodity/model/vo/ArticleListVo.java

@@ -0,0 +1,43 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 文章列表
+ *
+ * @author : Charles
+ * @date : 2021/4/8
+ */
+@Data
+public class ArticleListVo implements Serializable {
+    /** 阿里云索引Id */
+    private Integer mainId;
+    /** 文章ID */
+    private Integer articleId;
+    /** 文章标题 */
+    private String title;
+    /** 文章主图 */
+    private String image;
+    /** 文章作者 */
+    private String publisher;
+    /** 发布日期 */
+    private String publishDate;
+    /** 文章摘要 */
+    private String intro;
+    /** 文章内容 */
+    private String content;
+    /** 浏览量 */
+    private Integer pv;
+    /** 信息分类Id */
+    private Integer typeId;
+    /** 信息分类文本 */
+    private String typeText;
+    /** 标签 id数组 */
+    private String labelIds;
+    /** 标签 文本数组 */
+    private String labelText;
+
+    private static final long serialVersionUID = 1L;
+}

+ 25 - 0
src/main/java/com/caimei365/commodity/model/vo/EquipmentListVo.java

@@ -0,0 +1,25 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 项目仪器列表
+ *
+ * @author : Charles
+ * @date : 2021/4/8
+ */
+@Data
+public class EquipmentListVo implements Serializable {
+    /** 阿里云索引Id */
+    private Integer mainId;
+    /** 网页ID */
+    private Integer id;
+    /** 网页标题 */
+    private String name;
+    /** 主图 */
+    private String image;
+
+    private static final long serialVersionUID = 1L;
+}

+ 2 - 2
src/main/java/com/caimei365/commodity/model/vo/ProductListVo.java

@@ -12,8 +12,8 @@ import java.io.Serializable;
  */
 @Data
 public class ProductListVo implements Serializable {
-    /** 索引Id */
-    private Integer id;
+    /** 阿里云索引Id */
+    private Integer mainId;
     /** 商品productID */
     private Integer productId;
     /** 名称name */

+ 2 - 2
src/main/java/com/caimei365/commodity/model/vo/ShopListVo.java

@@ -13,8 +13,8 @@ import java.util.List;
  */
 @Data
 public class ShopListVo implements Serializable {
-    /** 索引Id */
-    private Integer id;
+    /** 阿里云索引Id */
+    private Integer mainId;
     /** 供应商Id */
     private Integer shopId;
     /** 名称name */

+ 40 - 2
src/main/java/com/caimei365/commodity/service/SearchQueryService.java

@@ -13,7 +13,7 @@ import java.util.Map;
  */
 public interface SearchQueryService {
     /**
-     * 获取索引Id
+     * 获取阿里云索引Id
      *
      * @param docType 文档类型
      * @param docId   文档ID
@@ -21,7 +21,7 @@ public interface SearchQueryService {
      */
     Integer getIdByDocId(String docType, Integer docId);
     /**
-     * 根据文档类型获取索引Id集合
+     * 根据文档类型获取阿里云索引Id集合
      * @param docType 文档类型
      * @return map
      */
@@ -63,4 +63,42 @@ public interface SearchQueryService {
      * @return JsonStr(list)
      */
     ResponseJson<String> queryEquipmentByKeyword(String keyword, int pageNum, int pageSize);
+
+    /**
+     * 根据关键词搜索文章
+     *
+     * @param keyword  搜索关键字
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize);
+
+    /**
+     * 根据文章ID搜索文章
+     *
+     * @param id 文章id
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> queryArticleByArticleId(Integer id);
+
+    /**
+     * 根据分类搜索文章
+     *
+     * @param id 分类id
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> queryArticleByType(Integer id, int pageNum, int pageSize);
+
+    /**
+     * 根据标签搜索文章
+     *
+     * @param id 标签id
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> queryArticleByLabel(Integer id, int pageNum, int pageSize);
 }

+ 15 - 75
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -99,7 +99,7 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
         SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
         // 阿里云搜索(滚动查询)
-        ResponseJson<String> result = deepPagingForParams(searchParams, queryStr, pageNum, pageSize, requestSize, requestPageSize);
+        ResponseJson<String> result = getScrollProductResult(searchParams, queryStr, requestPageSize, pageNum, pageSize);
         if (0 == result.getCode()) {
             return result;
         } else {
@@ -135,7 +135,7 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
         SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
         // 阿里云搜索(滚动查询)
-        ResponseJson<String> result = deepPagingForParams(searchParams, queryStr, pageNum, pageSize, requestSize, requestPageSize);
+        ResponseJson<String> result = getScrollProductResult(searchParams, queryStr, requestPageSize, pageNum, pageSize);
         if (0 == result.getCode()) {
             return result;
         } else {
@@ -170,7 +170,7 @@ public class SearchProductServiceImpl implements SearchProductService {
                 requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
             }
             SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
-            result = deepPagingForParams(searchParams, queryStr, pageNum, pageSize, requestSize, requestPageSize);
+            result = getScrollProductResult(searchParams, queryStr, requestPageSize, pageNum, pageSize);
         } else {
             String queryStr = "product:'" + keyword + "'";
             String filter = "p_supplier_id=" + id;
@@ -243,9 +243,8 @@ public class SearchProductServiceImpl implements SearchProductService {
             // 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
             searchParams = searchOpenService.getProductParams(queryStr, filter, identity,1, requestSize, sortField, sortType);
         }
-        // 查询推送
         try {
-// 查询推送
+            // 查询推送
             JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
             if (1 == result.getInt("status")) {
                 int total = result.getInt("total");
@@ -292,88 +291,29 @@ public class SearchProductServiceImpl implements SearchProductService {
      * 滚动查询
      *
      * @param searchParams  查询参数对象
-     * @param queryStr 查询类型及参数串
+     * @param queryStr      查询类型及参数串
+     * @param requestPageSize  每次scroll数量
      * @param pageNum       页码
      * @param pageSize      每页数量
-     * @param requestSize   请求总数量
-     * @param requestPageSize  每次scroll数量
      * @return list
      */
-    private ResponseJson<String> deepPagingForParams(SearchParams searchParams, String queryStr, int pageNum, int pageSize, int requestSize, int requestPageSize) {
-        //设置scroll方式查询
-        DeepPaging deep =new DeepPaging();
-        //不设置默认为1m表示1分钟,该参数表示本次返回的scrollid的有效期
-        deep.setScrollExpire("3m");
-        //添加DeepPaging对象参数
-        searchParams.setDeepPaging(deep);
-        // 查询推送
+    private ResponseJson<String> getScrollProductResult(SearchParams searchParams, String queryStr, int requestPageSize, int pageNum, int pageSize) {
+        ResponseJson<String> result;
         try {
-            // 查询推送
-            JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
-            if (1 == result.getInt("status")) {
-                int total = result.getInt("total");
-                int totalPage = (int) Math.ceil( (double)total/pageSize);
-                JSONArray pageData = new JSONArray();
-                int loop = (int)Math.ceil((double) requestSize / requestPageSize);
-                for (int l=1; l<=loop; l++) {
-                    //第一次执行不返回数据,主要返回scroll_id值,第二次调用查询时设置scroll_id
-                    deep.setScrollId(result.getString("scroll_id"));
-                    //不设置默认为1m表示1分钟,如不想使用默认值,每次重新调用前必须要重新设置下
-                    deep.setScrollExpire("3m");
-                    // 查询推送
-                    result = searchOpenService.getResultJsonObject(queryStr, searchParams);
-                    if (1 == result.getInt("status")) {
-                        JSONArray resultArr = result.getJSONArray("items");
-                        if (resultArr.length()>0){
-                            if (requestSize > SEARCH_MAX_NUM){
-                                if (l==loop) {
-                                    int baseSize = Math.min(requestSize - (requestPageSize*(loop-1)), resultArr.length());
-                                    // 上一页数量往前总数量 - 上一轮循环后总数量 = 当前循环的上一页之前数量
-                                    int baseNum = pageSize*(pageNum-1) - requestPageSize*(loop-1);
-                                    for (int i=0; i<pageSize; i++) {
-                                        int index = baseNum + i;
-                                        if (index<baseSize){
-                                            JSONObject item = resultArr.getJSONObject(index);
-                                            pageData.put(i, item);
-                                        } else {
-                                            break;
-                                        }
-                                    }
-                                }
-                            } else {
-                                int baseNum = (pageNum-1)*pageSize;
-                                int currentTotal = requestSize;
-                                if (totalPage == pageNum){
-                                    currentTotal = total;
-                                }
-                                for (int i=0; i<pageSize; i++) {
-                                    int index = baseNum + i;
-                                    if (index<currentTotal){
-                                        JSONObject item = resultArr.getJSONObject(index);
-                                        pageData.put(i, item);
-                                    } else {
-                                        break;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
+            JSONObject pageObj = searchOpenService.deepPagingForParams(searchParams, queryStr, SEARCH_MAX_NUM, requestPageSize, pageNum, pageSize);
+            if (1 == pageObj.getInt("status")){
+                JSONArray pageData = pageObj.getJSONArray("items");
                 // 阿里云查询出json转换成商品pojo
                 List<ProductListVo> productList = Json2PojoUtil.toProductList(pageData);
-                JSONObject pageObj = new JSONObject();
-                pageObj.put("total", total);
                 pageObj.put("items", productList);
-                log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
-                return ResponseJson.success(pageObj.toString());
+                result = ResponseJson.success(pageObj.toString());
             } else {
-                return ResponseJson.error("未查询到文档记录", null);
+                result = ResponseJson.error("未查询到文档记录", null);
             }
         } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
             log.error("查询文档异常:" + e.getMessage());
-            return ResponseJson.error("查询文档异常:" + e.getMessage(), null);
+            result = ResponseJson.error("查询文档异常:" + e.getMessage(), null);
         }
+        return result;
     }
-
-
 }

+ 273 - 18
src/main/java/com/caimei365/commodity/service/impl/SearchQueryServiceImpl.java

@@ -11,9 +11,7 @@ import com.aliyun.opensearch.sdk.generated.search.*;
 import com.caimei365.commodity.components.SearchOpenService;
 import com.caimei365.commodity.mapper.SearchMapper;
 import com.caimei365.commodity.model.ResponseJson;
-import com.caimei365.commodity.model.vo.PageVo;
-import com.caimei365.commodity.model.vo.ProductListVo;
-import com.caimei365.commodity.model.vo.ShopListVo;
+import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.SearchQueryService;
 import com.caimei365.commodity.utils.Json2PojoUtil;
 import com.github.pagehelper.PageHelper;
@@ -47,7 +45,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
     private SearchOpenService searchOpenService;
 
     /**
-     * 获取索引Id
+     * 获取阿里云索引Id
      *
      * @param docType 文档类型
      * @param docId   文档ID
@@ -67,16 +65,16 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         SearchParams searchParams = new SearchParams(config);
         if (null != docId) {
             if("product".equals(docType)) {
-                // 根据商品Id获取索引Id
+                // 根据商品Id获取阿里云索引Id
                 searchParams.setQuery("p_id:'" + docId + "'");
             } else if("shop".equals(docType)) {
-                // 根据供应商Id获取索引Id
+                // 根据供应商Id获取阿里云索引Id
                 searchParams.setQuery("s_id:'" + docId + "'");
             } else if("equipment".equals(docType)) {
-                // 根据项目仪器Id获取索引Id
+                // 根据项目仪器Id获取阿里云索引Id
                 searchParams.setQuery("e_id:'" + docId + "'");
             } else if("article".equals(docType)) {
-                // 根据文章Id获取索引Id
+                // 根据文章Id获取阿里云索引Id
                 searchParams.setQuery("a_id:'" + docId + "'");
             }
         } else {
@@ -98,13 +96,13 @@ public class SearchQueryServiceImpl implements SearchQueryService {
                 return -1;
             }
         } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
-            log.error("查询文档索引Id异常:" + e);
+            log.error("查询文档阿里云索引Id异常:" + e);
             return -1;
         }
     }
 
     /**
-     * 根据文档类型获取索引Id集合
+     * 根据文档类型获取阿里云索引Id集合
      *
      * @param docType  文档类型
      * @param pageNum   页码
@@ -153,7 +151,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
             }
             return idMap;
         } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
-            log.error("查询文档索引Id异常:" + e);
+            log.error("查询文档阿里云索引Id异常:" + e);
             return idMap;
         }
     }
@@ -204,7 +202,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
                 return -1;
             }
         } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
-            log.error("查询文档索引Id异常:" + e);
+            log.error("查询文档阿里云索引Id异常:" + e);
             return -1;
         }
     }
@@ -303,9 +301,268 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         if (StringUtils.isEmpty(keyword)) {
             queryStr = "e_all:'1'";
         }
-        return queryEquipment(queryStr, pageNum, pageSize);
+        // 阿里云搜索
+        ResponseJson<String> result = queryEquipment(queryStr, pageNum, pageSize);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryEquipmentFromDatabase(pageNum, pageSize, keyword);
+        }
+    }
+
+    /**
+     * 根据关键词搜索文章
+     *
+     * @param keyword  搜索关键字
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize) {
+        String queryStr = "article:'" + keyword + "'";
+        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
+        List<Map<String, String>> summaryList = new ArrayList<>(2);
+        Map<String, String> summaryField = new HashMap<>(2);
+        summaryField.put("length", "100");
+        summaryField.put("field", "a_title");
+        summaryList.add(summaryField);
+        Map<String, String> summaryField2 = new HashMap<>(2);
+        summaryField2.put("length", "200");
+        summaryField2.put("field", "a_intro");
+        summaryList.add(summaryField2);
+        // 阿里云搜索
+        ResponseJson<String> result = queryArticleForParams(queryStr, fetchFields, summaryList, pageNum, pageSize, null, 1);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryArticleFromDatabase(pageNum, pageSize, keyword, null, null, null);
+        }
+    }
+
+    /**
+     * 根据文章ID搜索文章
+     *
+     * @param id 文章id
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> queryArticleByArticleId(Integer id) {
+        String queryStr = "a_id:'" + id + "'";
+        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
+        // 阿里云搜索
+        ResponseJson<String> result = queryArticleForParams(queryStr, fetchFields, null, 1, 1, null, 1);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryArticleFromDatabase(1, 1, null, id, null, null);
+        }
+    }
+
+    /**
+     * 根据分类搜索文章
+     *
+     * @param id       分类id
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> queryArticleByType(Integer id, int pageNum, int pageSize) {
+        String queryStr = "a_type:'" + id + "'";
+        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
+        // 阿里云搜索
+        ResponseJson<String> result = scrollArticleForParams(queryStr, fetchFields, pageNum, pageSize, "a_id", 1);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryArticleFromDatabase(pageNum, pageSize, null, null, id, null);
+        }
+    }
+
+    /**
+     * 根据标签搜索文章
+     *
+     * @param id       标签id
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> queryArticleByLabel(Integer id, int pageNum, int pageSize) {
+        String queryStr = "a_label:'" + id + "'";
+        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
+        // 阿里云搜索
+        ResponseJson<String> result = scrollArticleForParams(queryStr, fetchFields, pageNum, pageSize, "a_id", 1);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryArticleFromDatabase(pageNum, pageSize, null, null, null, id);
+        }
     }
 
+    /**
+     * 文章查询(数据库)
+     *
+     * @param keyword       关键词
+     * @param articleId     文章Id
+     * @param typeId        分类Id
+     * @param labelId       标签Id
+     * @param num           页码
+     * @param size          每页数量
+     */
+    private ResponseJson<String> queryArticleFromDatabase(int num, int size, String keyword, Integer articleId, Integer typeId, Integer labelId) {
+        String labelText = null;
+        if (null != labelId){
+            labelText = searchMapper.findLabelNameById(labelId);
+        }
+        PageHelper.startPage(num, size);
+        List<ArticleListVo> articleList = searchMapper.queryArticle(keyword, articleId, typeId, labelText);
+        PageVo<ArticleListVo> pageData = new PageVo<>(articleList);
+        int total = pageData.getTotalRecord();
+        JSONObject pageObj = new JSONObject();
+        pageObj.put("total", total);
+        pageObj.put("items", articleList);
+        log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
+        if (articleList.size()>0) {
+            return ResponseJson.success(pageObj.toString());
+        } else {
+            return ResponseJson.error("未查询到文档记录(数据库)", null);
+        }
+    }
+
+    /**
+     * 文章查询
+     *
+     * @param queryStr      查询类型及参数
+     * @param fetchFields   返回字段
+     * @param summaryFields 摘要字段
+     * @param num           页码
+     * @param size          每页数量
+     */
+    private ResponseJson<String> queryArticleForParams(String queryStr, ArrayList<String> fetchFields, List<Map<String, String>> summaryFields, int num, int size, String sortField, Integer sortType) {
+        SearchParams searchParams;
+        int requestSize = num*size;
+        // 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
+        if (requestSize > SEARCH_MAX_NUM){
+            searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryFields, "article", num, size, sortField, sortType);
+        } else {
+            searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryFields, "article", 1, requestSize, sortField, sortType);
+        }
+        try {
+            // 查询推送
+            JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
+            if (1 == result.getInt("status")) {
+                int total = result.getInt("total");
+                int totalPage = (int) Math.ceil( (double)total/size);
+                JSONArray resultArr = result.getJSONArray("items");
+                JSONArray pageData = new JSONArray();
+                if (requestSize > SEARCH_MAX_NUM) {
+                    pageData = resultArr;
+                } else {
+                    if (resultArr.length()>0){
+                        int baseNum = (num-1)*size;
+                        for (int i=0; i<size; i++) {
+                            int index = baseNum + i;
+                            int currentTotal = requestSize;
+                            if (totalPage == num){
+                                currentTotal = total;
+                            }
+                            if (index<currentTotal){
+                                JSONObject item = resultArr.getJSONObject(index);
+                                pageData.put(i, item);
+                            } else {
+                                break;
+                            }
+                        }
+                    }
+                }
+                // 阿里云查询出json转换成文章pojo
+                List<ArticleListVo> articleList = Json2PojoUtil.toArticleList(pageData);
+                JSONObject pageObj = new JSONObject();
+                pageObj.put("total", total);
+                pageObj.put("items", articleList);
+                log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + size +"),pageNum("+num+"),total("+total+")");
+                return ResponseJson.success(pageObj.toString());
+            } else {
+                return ResponseJson.error("未查询到文档记录", null);
+            }
+        } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
+            log.error("查询文档异常:" + e.getMessage());
+            return ResponseJson.error("查询文档异常:" + e.getMessage(), null);
+        }
+    }
+
+    /**
+     * 滚动查询文章数据
+     *
+     * @param queryStr  查询类型及参数
+     * @param pageNum       页码
+     * @param pageSize      每页数量
+     * @param sortField 排序字段
+     * @param sortType  升降序
+     */
+    private ResponseJson<String> scrollArticleForParams(String queryStr, ArrayList<String> fetchFields, int pageNum, int pageSize, String sortField, Integer sortType) {
+        int requestSize = pageNum*pageSize;
+        int requestPageSize = requestSize;
+        if (requestSize > SEARCH_MAX_NUM){
+            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+        }
+        SearchParams searchParams = searchOpenService.getScrollParams(queryStr, fetchFields, requestPageSize, sortField, sortType);
+        ResponseJson<String> result;
+        try {
+            JSONObject pageObj = searchOpenService.deepPagingForParams(searchParams, queryStr, SEARCH_MAX_NUM, requestPageSize, pageNum, pageSize);
+            if (1 == pageObj.getInt("status")){
+                JSONArray pageData = pageObj.getJSONArray("items");
+                // 阿里云查询出json转换成商品pojo
+                List<ArticleListVo> articleList = Json2PojoUtil.toArticleList(pageData);
+                pageObj.put("items", articleList);
+                result = ResponseJson.success(pageObj.toString());
+            } else {
+                result = ResponseJson.error("未查询到文档记录", null);
+            }
+        } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
+            log.error("查询文档异常:" + e.getMessage());
+            result = ResponseJson.error("查询文档异常:" + e.getMessage(), null);
+        }
+        return result;
+    }
+
+    /**
+     * 获取项目仪器(数据库)
+     *
+     * @param num       页码
+     * @param size      每页数量
+     * @param keyword   关键词
+     */
+    private ResponseJson<String> queryEquipmentFromDatabase(int num, int size, String keyword) {
+        PageHelper.startPage(num, size);
+        List<EquipmentListVo> equipmentList = searchMapper.queryEquipment(keyword);
+        PageVo<EquipmentListVo> pageData = new PageVo<>(equipmentList);
+        int total = pageData.getTotalRecord();
+        JSONObject pageObj = new JSONObject();
+        pageObj.put("total", total);
+        pageObj.put("items", equipmentList);
+        log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
+        if (equipmentList.size()>0) {
+            return ResponseJson.success(pageObj.toString());
+        } else {
+            return ResponseJson.error("未查询到文档记录(数据库)", null);
+        }
+    }
+
+    /**
+     * 查询项目仪器(阿里云搜索)
+     *
+     * @param queryStr  查询类型及参数
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     */
     private ResponseJson<String> queryEquipment(String queryStr, int pageNum, int pageSize) {
         ArrayList<String> fetchFields = Lists.newArrayList("id", "e_id", "e_name", "e_image");
         List<Map<String, String>> summaryList = new ArrayList<>(1);
@@ -321,7 +578,6 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         } else {
             searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryList, "equipment", 1, requestSize, null, null);
         }
-        // 查询推送
         try {
             // 查询推送
             JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
@@ -350,9 +606,11 @@ public class SearchQueryServiceImpl implements SearchQueryService {
                         }
                     }
                 }
+                // 阿里云查询出json转换项目仪器pojo
+                List<EquipmentListVo> equipmentList = Json2PojoUtil.toEquipmentList(pageData);
                 JSONObject pageObj = new JSONObject();
                 pageObj.put("total", total);
-                pageObj.put("items", pageData);
+                pageObj.put("items", equipmentList);
                 log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
                 return ResponseJson.success(pageObj.toString());
             } else {
@@ -364,8 +622,6 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         }
     }
 
-
-
     /**
      * 获取供应商(数据库)
      *
@@ -413,7 +669,6 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         } else {
             searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, null, "supplier", 1, requestSize, "s_sort", 1);
         }
-        // 查询推送
         try {
             // 查询推送
             JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);

+ 70 - 2
src/main/java/com/caimei365/commodity/utils/Json2PojoUtil.java

@@ -2,6 +2,8 @@ package com.caimei365.commodity.utils;
 
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONArray;
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONObject;
+import com.caimei365.commodity.model.vo.ArticleListVo;
+import com.caimei365.commodity.model.vo.EquipmentListVo;
 import com.caimei365.commodity.model.vo.ProductListVo;
 import com.caimei365.commodity.model.vo.ShopListVo;
 
@@ -26,7 +28,7 @@ public class Json2PojoUtil {
         for (int i=0; i<jsonArray.length(); i++) {
             JSONObject json = jsonArray.getJSONObject(i);
             /* 主键Id */
-            product.setId(json.getInt("id"));
+            product.setMainId(json.getInt("id"));
             /* 商品Id */
             product.setProductId(json.getInt("p_id"));
             /* 名称name */
@@ -66,7 +68,7 @@ public class Json2PojoUtil {
         for (int i=0; i<jsonArray.length(); i++) {
             JSONObject json = jsonArray.getJSONObject(i);
             /* 主键Id */
-            shop.setId(json.getInt("id"));
+            shop.setMainId(json.getInt("id"));
             /* 供应商Id */
             shop.setShopId(json.getInt("s_id"));
             /* 供应商名称name */
@@ -89,4 +91,70 @@ public class Json2PojoUtil {
         return shopList;
 
     }
+
+    /**
+     * 阿里云查询出json转换项目仪器pojo
+     * @param jsonArray json
+     * @return ShopListVo
+     */
+    public static List<EquipmentListVo> toEquipmentList(JSONArray jsonArray) {
+        List<EquipmentListVo> equipmentList = new ArrayList<>();
+        EquipmentListVo equipment = new EquipmentListVo();
+        for (int i=0; i<jsonArray.length(); i++) {
+            JSONObject json = jsonArray.getJSONObject(i);
+            /* 阿里云索引Id */
+            equipment.setMainId(json.getInt("id"));
+            /* 网页ID */
+            equipment.setId(json.getInt("e_id"));
+            /* 网页标题 */
+            equipment.setName(json.getString("e_name"));
+            /* 主图 */
+            equipment.setImage(json.getString("e_image"));
+
+            equipmentList.add(equipment);
+        }
+        return equipmentList;
+    }
+
+    /**
+     * 阿里云查询出json转换成文章pojo
+     * @param jsonArray json
+     * @return ShopListVo
+     */
+    public static List<ArticleListVo> toArticleList(JSONArray jsonArray) {
+        List<ArticleListVo> articleList = new ArrayList<>();
+        ArticleListVo article = new ArticleListVo();
+        for (int i=0; i<jsonArray.length(); i++) {
+            JSONObject json = jsonArray.getJSONObject(i);
+            /* 阿里云索引Id */
+            article.setMainId(json.getInt("id"));
+            /* 文章ID */
+            article.setArticleId(json.getInt("a_id"));
+            /* 文章标题 */
+            article.setTitle(json.getString("a_title"));
+            /* 文章主图 */
+            article.setImage(json.getString("a_image"));
+            /* 文章作者 */
+            article.setPublisher(json.getString("a_publisher"));
+            /* 发布日期 */
+            article.setPublishDate(json.getString("a_publish_date"));
+            /* 文章摘要 */
+            article.setIntro(json.getString("a_intro"));
+            /* 浏览量 */
+            article.setPv(json.getInt("a_pv"));
+            /* 信息分类Id */
+            article.setTypeId(json.getInt("a_type_id"));
+            /* 信息分类文本 */
+            article.setTypeText(json.getString("a_type_text"));
+            /* 标签 id数组 */
+            article.setLabelIds(json.getString("a_label_ids"));
+            /* 标签 文本数组 */
+            article.setLabelText(json.getString("a_label_text"));
+
+            articleList.add(article);
+        }
+        return articleList;
+    }
+
+
 }

+ 40 - 120
src/main/resources/mapper/SearchMapper.xml

@@ -259,7 +259,13 @@
 		group by name
 		order by clickRate desc
     </select>
-
+    <select id="findLabelNameById" resultType="java.lang.String">
+		select name
+		from info_label
+		where  infoLabelStatus = 1
+		and id = #{labelId}
+		limit 1
+    </select>
     <!-- 搜索容错 商品列表 -->
     <select id="queryProduct" resultType="com.caimei365.commodity.model.vo.ProductListVo">
         select
@@ -342,12 +348,12 @@
     <!-- 搜索容错 供应商列表 -->
     <select id="querySupplier" resultType="com.caimei365.commodity.model.vo.ShopListVo">
         select
-        s.shopID as shopId,
-        s.name as name,
-        s.logo as logo,
-        s.authorizationCertificateImage as license,
-        s.businessScope as business,
-        CONCAT(p.name, c.name) as address
+            s.shopID as shopId,
+            s.name as name,
+            s.logo as logo,
+            s.authorizationCertificateImage as license,
+            s.businessScope as business,
+            CONCAT(p.name, c.name) as address
         from shop as s
         left join town as t on s.townId = t.townID
         left join city as c on t.cityID = c.cityID
@@ -356,136 +362,51 @@
         and shopID != 1252
         and s.name like concat('%',#{keyword},'%')
     </select>
-
-
-
-
-
-
-
-
-
-
-
-    <select id="searchDbSupplierByKeyword" resultType="com.caimei365.commodity.model.search.SupplierDO">
+    <!-- 搜索容错 项目仪器列表 -->
+    <select id="queryEquipment" resultType="com.caimei365.commodity.model.vo.EquipmentListVo">
         select
-        s.shopID as s_id,
-        s.businessScope as s_business,
-        s.authorizationCertificateImage as s_license,
-        s.name as s_name,
-        s.logo as s_logo,
-        s.townID as s_town_id,
-        CONCAT(p.name, c.name) as s_address,
-        s.sortIndex as s_sort,
-        s.status as s_valid
-        from shop as s
-        left join town as t on s.townId = t.townID
-        left join city as c on t.cityID = c.cityID
-        left join province as p on c.provinceID = p.provinceID
-        where (status = 90 or status = 9)
-        and shopID != 1252
-        and s.name like concat('%',#{keyword},'%')
-    </select>
-
-
-    <select id="searchDbEquipmentByKeyword" resultType="com.caimei365.commodity.model.search.EquipmentDO">
-        select <include refid="Search_Equipment_List"/>
+            e.id as id,
+            e.title as name,
+            e.precisehKey as keyword,
+            e.headImage as image
         from cm_page as e
         where e.type = 2 and e.enabledStatus = 1
         and e.title like concat('%',#{keyword},'%')
         order by e.docBoost desc
     </select>
-
-    <select id="searchDbProduct" resultType="com.caimei365.commodity.model.search.ProductDO">
-        select <include refid="Search_Product_List"/>, p.productCategory
-        from product as p
-        <include refid="Product_Joins"/>
-        <where>
-            <choose>
-                <when test="identity == 1">
-                    p.validFlag in (2,3,9) and p.productCategory = 1
-                </when>
-                <when test="identity == 2">
-                    p.validFlag = 2 and p.productCategory = 1
-                </when>
-                <when test="identity == 4">
-                    p.visibility in (2,3) and p.validFlag = 2 and p.productCategory = 1
-                </when>
-                <otherwise>
-                    p.visibility = 3 and p.validFlag = 2 and p.productCategory = 1
-                </otherwise>
-            </choose>
-            <if test="keyword != null and keyword != ''">
-                and p.name LIKE concat('%',#{keyword},'%')
-            </if>
-            <if test="shopID != null">
-                and sh.shopID = #{shopID}
-            </if>
-            <if test="typeId != null">
-                <choose>
-                    <when test="idType == 1">
-                        and p.bigTypeId = #{typeId}
-                    </when>
-                    <when test="idType == 2">
-                        and p.smallTypeId = #{typeId}
-                    </when>
-                    <when test="idType == 3">
-                        and p.tinyTypeId = #{typeId}
-                    </when>
-                </choose>
-            </if>
-        </where>
-        <choose>
-            <when test="sortField != null and sortField != ''">
-                <choose>
-                    <when test="sortField == 'p_price'">
-                        order by p.price1
-                    </when>
-                    <when test="sortField == 'p_sales'">
-                        order by p.sellNumber
-                    </when>
-                    <when test="sortField == 'p_favorite'">
-                        order by p.favoriteTimes
-                    </when>
-                    <otherwise>
-                        order by p.productID
-                    </otherwise>
-                </choose>
-            </when>
-            <otherwise>
-                order by p.productID
-            </otherwise>
-        </choose>
-        <choose>
-            <when test="sortType == 1">
-                desc
-            </when>
-            <otherwise>
-                asc
-            </otherwise>
-        </choose>
-    </select>
-    <select id="searchDbArticle" resultType="com.caimei365.commodity.model.search.DbArticleDO">
-        select <include refid="Search_Article_List"/>
+    <!-- 搜索容错 文章列表 -->
+    <select id="queryArticle" resultType="com.caimei365.commodity.model.vo.ArticleListVo">
+        select
+            a.id as articleId,
+            a.title as title,
+            a.guidanceImage as image,
+            a.publisher as publisher,
+            a.pubdate as publishDate,
+            a.recommendContent as intro,
+            (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
+            a.typeId as typeId,
+            b.name as typeText,
+            a.label as labelText,
         from info as a
-        <include refid="Article_Joins"/>
+		left join info_type b on a.typeId = b.id
+		left join info_praise c on a.id = c.infoId
         <where>
             a.enabledStatus = 1
             <if test="articleId != null">
                 and a.id = #{articleId}
             </if>
-            <if test="keyword != null and keyword != ''">
-                and a.title like concat ('%',#{keyword},'%')
-            </if>
             <if test="typeId != null">
                 and a.typeId = #{typeId}
             </if>
-            <if test="labelId != null">
-                and a.label = #{labelId}
+            <if test="keyword != null and keyword != ''">
+                and a.title like concat ('%',#{keyword},'%')
+            </if>
+            <if test="labelText != null">
+                and a.label like concat ('%',#{labelText},'%')
             </if>
         </where>
         <choose>
-            <when test="typeId != null or labelId != null">
+            <when test="typeId != null or labelText != null">
                 order by a.id desc
             </when>
             <otherwise>
@@ -493,5 +414,4 @@
             </otherwise>
         </choose>
     </select>
-
 </mapper>