"ruoyi-ui/src/git@ustchcs.com:gujinli1118/RuoYi-Vue.git" did not exist on "d5cc95fefbb7dea269602b8b20d67c368d905369"
Commit 485aec3f authored by macro's avatar macro
Browse files

搜索功能查询结果为空问题修复

parent fe2f43f3
package com.macro.mall.search.service.impl; package com.macro.mall.search.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.macro.mall.search.dao.EsProductDao; import com.macro.mall.search.dao.EsProductDao;
import com.macro.mall.search.domain.EsProduct; import com.macro.mall.search.domain.EsProduct;
...@@ -162,7 +163,7 @@ public class EsProductServiceImpl implements EsProductService { ...@@ -162,7 +163,7 @@ public class EsProductServiceImpl implements EsProductService {
LOGGER.info("DSL:{}", searchQuery.getQuery().toString()); LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class); SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
if(searchHits.getTotalHits()<=0){ if(searchHits.getTotalHits()<=0){
return new PageImpl<>(null,pageable,0); return new PageImpl<>(ListUtil.empty(),pageable,0);
} }
List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList()); List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits()); return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
...@@ -206,12 +207,12 @@ public class EsProductServiceImpl implements EsProductService { ...@@ -206,12 +207,12 @@ public class EsProductServiceImpl implements EsProductService {
LOGGER.info("DSL:{}", searchQuery.getQuery().toString()); LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class); SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
if(searchHits.getTotalHits()<=0){ if(searchHits.getTotalHits()<=0){
return new PageImpl<>(null,pageable,0); return new PageImpl<>(ListUtil.empty(),pageable,0);
} }
List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList()); List<EsProduct> searchProductList = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits()); return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
} }
return new PageImpl<>(null); return new PageImpl<>(ListUtil.empty());
} }
@Override @Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment