JAVA全系列 教程
3762个小节阅读:7089.6k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在搜索服务模块编写商品Repository
xxxxxxxxxx
@Repository
public interface GoodsESRepository extends ElasticsearchRepository<GoodsES,Long> {
}
在搜索服务接口实现类编写向ES同步商品数据方法
xxxxxxxxxx
// 向ES同步商品数据
@Override
public void syncGoodsToES(GoodsDesc goodsDesc) {
// 将商品详情对象转为GoodsES对象
GoodsES goodsES = new GoodsES();
goodsES.setId(goodsDesc.getId());
goodsES.setGoodsName(goodsDesc.getGoodsName());
goodsES.setCaption(goodsDesc.getCaption());
goodsES.setPrice(goodsDesc.getPrice());
goodsES.setHeaderPic(goodsDesc.getHeaderPic());
goodsES.setBrand(goodsDesc.getBrand().getName());
// 类型集合
List<String> productType = new ArrayList();
productType.add(goodsDesc.getProductType1().getName());
productType.add(goodsDesc.getProductType2().getName());
productType.add(goodsDesc.getProductType3().getName());
goodsES.setProductType(productType);
// 规格集合
Map<String,List<String>> map = new HashMap();
List<Specification> specifications = goodsDesc.getSpecifications();
// 遍历规格
for (Specification specification : specifications) {
// 规格项集合
List<SpecificationOption> options = specification.getSpecificationOptions();
// 规格项名集合
List<String> optionStrList = new ArrayList();
for (SpecificationOption option : options) {
optionStrList.add(option.getOptionName());
}
map.put(specification.getSpecName(),optionStrList);
}
goodsES.setSpecification(map);
// 关键字
List<String> tags = new ArrayList();
tags.add(goodsDesc.getBrand().getName()); //品牌名是关键字
tags.addAll(analyze(goodsDesc.getGoodsName(),"ik_smart"));//商品名分词后为关键词
tags.addAll(analyze(goodsDesc.getCaption(),"ik_smart"));//副标题分词后为关键词
goodsESRepository.save(goodsES);
}