搜索功能查询结果为空问题修复
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user