Commit 485aec3f authored by macro's avatar macro
Browse files

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

parent fe2f43f3
package com.macro.mall.search.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.macro.mall.search.dao.EsProductDao;
import com.macro.mall.search.domain.EsProduct;
......@@ -162,7 +163,7 @@ public class EsProductServiceImpl implements EsProductService {
LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
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());
return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
......@@ -206,12 +207,12 @@ public class EsProductServiceImpl implements EsProductService {
LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
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());
return new PageImpl<>(searchProductList,pageable,searchHits.getTotalHits());
}
return new PageImpl<>(null);
return new PageImpl<>(ListUtil.empty());
}
@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