use of com.xatu.gmall.entity.PmsSearchSkuInfo in project GMall by 18391713434.
the class SearchServiceImpl method list.
@Override
public List<PmsSearchSkuInfo> list(PmsSearchParam pmsSearchParam) {
String searchDsl = getSearchDsl(pmsSearchParam);
Search search = new Search.Builder(searchDsl).addIndex("gmall").addType("PmsSkuInfo").build();
SearchResult execute = null;
try {
execute = jestClient.execute(search);
} catch (Exception e) {
e.printStackTrace();
System.out.println("es未查询到数据");
}
ArrayList<PmsSearchSkuInfo> pmsSearchSkuInfoArrayList = new ArrayList<>();
List<SearchResult.Hit<PmsSearchSkuInfo, Void>> hits = null;
hits = execute.getHits(PmsSearchSkuInfo.class);
if (hits != null) {
for (SearchResult.Hit<PmsSearchSkuInfo, Void> hit : hits) {
PmsSearchSkuInfo source = hit.source;
Map<String, List<String>> hightlight = hit.highlight;
if (hightlight != null) {
String skuName = hightlight.get("skuName").get(0);
source.setSkuName(skuName);
}
pmsSearchSkuInfoArrayList.add(source);
}
}
return pmsSearchSkuInfoArrayList;
}
use of com.xatu.gmall.entity.PmsSearchSkuInfo in project GMall by 18391713434.
the class GmallSearchServiceApplicationTests method contextLoads.
@Test
public void contextLoads() throws IOException {
List<PmsSkuInfo> pmsSkuInfoList = new ArrayList<>();
pmsSkuInfoList = skuService.selectAllSku("61");
// 转换为es数据结构
List<PmsSearchSkuInfo> pmsSearchSkuInfoList = new ArrayList<>();
for (PmsSkuInfo pmsSkuInfo : pmsSkuInfoList) {
PmsSearchSkuInfo pmsSearchSkuInfo = new PmsSearchSkuInfo();
BeanUtils.copyProperties(pmsSkuInfo, pmsSearchSkuInfo);
pmsSearchSkuInfo.setProductId(pmsSkuInfo.getSpuId());
pmsSearchSkuInfoList.add(pmsSearchSkuInfo);
}
// 导入es
for (PmsSearchSkuInfo pmsSearchSkuInfo : pmsSearchSkuInfoList) {
String idStr = pmsSearchSkuInfo.getId().toString();
Index put = new Index.Builder(pmsSearchSkuInfo).index("com.xatu.gmall").type("PmsSkuInfo").id(idStr).build();
jestClient.execute(put);
}
}
Aggregations