diff --git a/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java b/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java index fec64277..c1d956be 100644 --- a/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java +++ b/framework/src/main/java/cn/lili/elasticsearch/BaseElasticsearchService.java @@ -85,6 +85,7 @@ public abstract class BaseElasticsearchService { */ protected void createIndexRequest(String index) { try { + deleteIndexRequest(index); CreateIndexRequest request = new CreateIndexRequest(index); //Settings for this index request.settings(Settings.builder() diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuDTO.java b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuDTO.java new file mode 100644 index 00000000..a93db09f --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuDTO.java @@ -0,0 +1,25 @@ +package cn.lili.modules.goods.entity.dto; + +import cn.lili.modules.goods.entity.dos.GoodsSku; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * @author paulG + * @since 2022/6/13 + **/ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +public class GoodsSkuDTO extends GoodsSku { + + private static final long serialVersionUID = 6600436187015048097L; + + @ApiModelProperty(value = "商品参数json") + private String params; + +} diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/vos/GoodsSkuVO.java b/framework/src/main/java/cn/lili/modules/goods/entity/vos/GoodsSkuVO.java index 32f3a030..4721a4c9 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/vos/GoodsSkuVO.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/vos/GoodsSkuVO.java @@ -5,6 +5,7 @@ import cn.lili.modules.goods.entity.dos.GoodsSku; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.List; @@ -16,6 +17,7 @@ import java.util.List; * @since 2020-02-26 23:24:13 */ @Data +@EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor public class GoodsSkuVO extends GoodsSku { diff --git a/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java b/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java index db3e0a58..e17f6d41 100644 --- a/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java +++ b/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java @@ -1,7 +1,11 @@ package cn.lili.modules.goods.mapper; import cn.lili.modules.goods.entity.dos.GoodsSku; +import cn.lili.modules.goods.entity.dto.GoodsSkuDTO; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Constants; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -99,4 +103,15 @@ public interface GoodsSkuMapper extends BaseMapper { ")") int replaceGoodsSku(@Param("goodsSku") GoodsSku goodsSku); + + /** + * 分页查询商品skuDTO + * + * @param page 分页 + * @param queryWrapper 查询条件 + * @return 售后VO分页 + */ + @Select("SELECT *,g.params as params FROM li_goods_sku gs inner join li_goods g on gs.goods_id = g.id ${ew.customSqlSegment}") + IPage queryByParams(IPage page, @Param(Constants.WRAPPER) Wrapper queryWrapper); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index 031fac67..754a5edf 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -5,9 +5,12 @@ import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsOperationDTO; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; +import cn.lili.modules.goods.entity.dto.GoodsSkuDTO; import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO; import cn.lili.modules.goods.entity.vos.GoodsSkuVO; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -136,6 +139,15 @@ public interface GoodsSkuService extends IService { */ IPage getGoodsSkuByPage(GoodsSearchParams searchParams); + + /** + * 分页查询商品sku信息 + * + * @param searchParams 查询参数 + * @return 商品sku信息 + */ + IPage getGoodsSkuDTOByPage(Page page, Wrapper queryWrapper); + /** * 列表查询商品sku信息 * diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index c4072466..c4d89278 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -18,6 +18,7 @@ import cn.lili.modules.goods.entity.dos.GoodsGallery; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsOperationDTO; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; +import cn.lili.modules.goods.entity.dto.GoodsSkuDTO; import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; @@ -44,9 +45,11 @@ import cn.lili.modules.search.utils.EsIndexUtil; import cn.lili.mybatis.util.PageUtil; import cn.lili.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.rocketmq.tags.GoodsTagsEnum; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -448,6 +451,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl i return this.page(PageUtil.initPage(searchParams), searchParams.queryWrapper()); } + @Override + public IPage getGoodsSkuDTOByPage(Page page, Wrapper queryWrapper) { + return this.baseMapper.queryByParams(page, queryWrapper); + } + /** * 列表查询商品sku信息 * diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java index ffb8d56a..199e7e79 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java @@ -29,7 +29,7 @@ public interface EsGoodsIndexService { * * @return */ - Map getProgress(); + Map getProgress(); /** @@ -106,8 +106,9 @@ public interface EsGoodsIndexService { * 初始化商品索引 * * @param goodsIndexList 商品索引列表 + * @param regeneratorIndex 是否重新生成索引 */ - void initIndex(List goodsIndexList); + void initIndex(List goodsIndexList, boolean regeneratorIndex); /** * 更新商品索引的促销信息 diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 2c999f64..773e603d 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -21,6 +21,7 @@ import cn.lili.elasticsearch.EsSuffix; import cn.lili.elasticsearch.config.ElasticsearchProperties; import cn.lili.modules.goods.entity.dos.*; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; +import cn.lili.modules.goods.entity.dto.GoodsSkuDTO; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum; @@ -38,6 +39,7 @@ import cn.lili.modules.search.service.EsGoodsSearchService; import cn.lili.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; @@ -83,6 +85,11 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements private final Map fieldMap = ReflectUtil.getFieldMap(EsGoodsIndex.class); + + private final String KEY_SUCCESS = "success"; + private final String KEY_FAIL = "fail"; + private final String KEY_PROCESSED = "processed"; + @Autowired private ElasticsearchProperties elasticsearchProperties; @Autowired @@ -128,7 +135,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); //为空则默认写入没有任务 if (flag == null) { - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false, 10L, TimeUnit.MINUTES); + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); } //有正在初始化的任务,则提示异常 if (Boolean.TRUE.equals(flag)) { @@ -137,48 +144,58 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements //初始化标识 cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true); + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true, 10L, TimeUnit.MINUTES); + ThreadUtil.execAsync(() -> { try { - LambdaQueryWrapper goodsQueryWrapper = new LambdaQueryWrapper<>(); - goodsQueryWrapper.eq(Goods::getAuthFlag, GoodsAuthEnum.PASS.name()); - goodsQueryWrapper.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name()); - goodsQueryWrapper.eq(Goods::getDeleteFlag, false); + QueryWrapper skuQueryWrapper = new QueryWrapper<>(); + skuQueryWrapper.eq("gs.auth_flag", GoodsAuthEnum.PASS.name()); + skuQueryWrapper.eq("gs.market_enable", GoodsStatusEnum.UPPER.name()); + skuQueryWrapper.eq("gs.delete_flag", false); + + + Map resultMap = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); + + if (CollUtil.isEmpty(resultMap)) { + QueryWrapper skuCountQueryWrapper = new QueryWrapper<>(); + skuCountQueryWrapper.eq("auth_flag", GoodsAuthEnum.PASS.name()); + skuCountQueryWrapper.eq("market_enable", GoodsStatusEnum.UPPER.name()); + skuCountQueryWrapper.eq("delete_flag", false); + resultMap = new HashMap<>(); + resultMap.put(KEY_SUCCESS, 0L); + resultMap.put(KEY_FAIL, 0L); + resultMap.put(KEY_PROCESSED, 0L); + resultMap.put("total", this.goodsSkuService.count(skuCountQueryWrapper)); + cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), resultMap); + } for (int i = 1; ; i++) { List esGoodsIndices = new ArrayList<>(); - IPage page = new Page<>(i, 1000); - IPage goodsIPage = goodsService.page(page, goodsQueryWrapper); - if (goodsIPage == null || CollUtil.isEmpty(goodsIPage.getRecords())) { + Page skuPage = new Page<>(i, 100); + IPage skuIPage = goodsSkuService.getGoodsSkuDTOByPage(skuPage, skuQueryWrapper); + if (skuIPage == null || CollUtil.isEmpty(skuIPage.getRecords())) { break; } - for (Goods goods : goodsIPage.getRecords()) { - LambdaQueryWrapper skuQueryWrapper = new LambdaQueryWrapper<>(); - skuQueryWrapper.eq(GoodsSku::getGoodsId, goods.getId()); - skuQueryWrapper.eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name()); - skuQueryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name()); - skuQueryWrapper.eq(GoodsSku::getDeleteFlag, false); - for (int j = 1; ; j++) { - IPage skuPage = new Page<>(j, 100); - IPage skuIPage = goodsSkuService.page(skuPage, skuQueryWrapper); - if (skuIPage == null || CollUtil.isEmpty(skuIPage.getRecords())) { - break; - } - int skuSource = 100; - for (GoodsSku goodsSku : skuIPage.getRecords()) { - EsGoodsIndex esGoodsIndex = wrapperEsGoodsIndex(goodsSku, goods); - esGoodsIndex.setSkuSource(skuSource--); - esGoodsIndices.add(esGoodsIndex); - //库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量 - cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); - } + for (GoodsSkuDTO goodsSku : skuIPage.getRecords()) { + int skuSource = 100; + EsGoodsIndex esGoodsIndex = wrapperEsGoodsIndex(goodsSku); + long count = esGoodsIndices.stream().filter(j -> j.getGoodsId().equals(esGoodsIndex.getGoodsId())).count(); + if (count >= 1) { + skuSource -= count; } + esGoodsIndex.setSkuSource(skuSource); + esGoodsIndices.add(esGoodsIndex); + //库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量 + cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); } - this.initIndex(esGoodsIndices); + + //批量插入索引,如果为第一次则删除原索引并创建新索引 + this.initIndex(esGoodsIndices, i == 1); } + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); //初始化商品索引 } catch (Exception e) { @@ -188,16 +205,17 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); } }); + } @Override - public Map getProgress() { - Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); + public Map getProgress() { + Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); if (map == null) { return Collections.emptyMap(); } Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); - map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); + map.put("flag", Boolean.TRUE.equals(flag) ? 1L : 0L); return map; } @@ -391,7 +409,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } @Override - public void initIndex(List goodsIndexList) { + public void initIndex(List goodsIndexList, boolean regeneratorIndex) { if (goodsIndexList == null || goodsIndexList.isEmpty()) { //初始化标识 cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); @@ -405,27 +423,18 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements //但是如果索引已经自动生成过,这里就不会创建索引,设置mapping,所以这里决定在初始化索引的同时,将已有索引删除,重新创建 //如果索引存在,则删除,重新生成。 这里应该有更优解。 - if (this.indexExist(indexName)) { - deleteIndexRequest(indexName); + boolean indexExist = this.indexExist(indexName); + if (regeneratorIndex || !indexExist) { + //如果索引不存在,则创建索引 + createIndexRequest(indexName); } - //如果索引不存在,则创建索引 - createIndexRequest(indexName); - Map resultMap = new HashMap<>(16); - final String KEY_SUCCESS = "success"; - final String KEY_FAIL = "fail"; - final String KEY_PROCESSED = "processed"; - resultMap.put("total", goodsIndexList.size()); - resultMap.put(KEY_SUCCESS, 0); - resultMap.put(KEY_FAIL, 0); - resultMap.put(KEY_PROCESSED, 0); - cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), resultMap); + Map resultMap = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); if (!goodsIndexList.isEmpty()) { - goodsIndexRepository.deleteAll(); for (EsGoodsIndex goodsIndex : goodsIndexList) { try { log.info("生成商品索引:{}", goodsIndex); - addIndex(goodsIndex); + this.addIndex(goodsIndex); resultMap.put(KEY_SUCCESS, resultMap.get(KEY_SUCCESS) + 1); } catch (Exception e) { log.error("商品{}生成索引错误!", goodsIndex); @@ -436,7 +445,6 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } } cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), resultMap); - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); } @Override @@ -813,30 +821,30 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements return elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME; } - private EsGoodsIndex wrapperEsGoodsIndex(GoodsSku goodsSku, Goods goods) { + private EsGoodsIndex wrapperEsGoodsIndex(GoodsSkuDTO goodsSku) { EsGoodsIndex index = new EsGoodsIndex(goodsSku); //商品参数索引 - if (goods.getParams() != null && !goods.getParams().isEmpty()) { - List goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class); + if (CharSequenceUtil.isNotEmpty(goodsSku.getParams())) { + List goodsParamDTOS = JSONUtil.toList(goodsSku.getParams(), GoodsParamsDTO.class); index = new EsGoodsIndex(goodsSku, goodsParamDTOS); } //商品分类索引 - if (goods.getCategoryPath() != null) { - List categories = categoryService.listByIdsOrderByLevel(Arrays.asList(goods.getCategoryPath().split(","))); + if (goodsSku.getCategoryPath() != null) { + List categories = categoryService.listByIdsOrderByLevel(Arrays.asList(goodsSku.getCategoryPath().split(","))); if (!categories.isEmpty()) { index.setCategoryNamePath(ArrayUtil.join(categories.stream().map(Category::getName).toArray(), ",")); } } //商品品牌索引 - Brand brand = brandService.getById(goods.getBrandId()); + Brand brand = brandService.getById(goodsSku.getBrandId()); if (brand != null) { index.setBrandName(brand.getName()); index.setBrandUrl(brand.getLogo()); } //店铺分类索引 - if (goods.getStoreCategoryPath() != null && CharSequenceUtil.isNotEmpty(goods.getStoreCategoryPath())) { - List storeGoodsLabels = storeGoodsLabelService.listByStoreIds(Arrays.asList(goods.getStoreCategoryPath().split(","))); + if (goodsSku.getStoreCategoryPath() != null && CharSequenceUtil.isNotEmpty(goodsSku.getStoreCategoryPath())) { + List storeGoodsLabels = storeGoodsLabelService.listByStoreIds(Arrays.asList(goodsSku.getStoreCategoryPath().split(","))); if (!storeGoodsLabels.isEmpty()) { index.setStoreCategoryNamePath(ArrayUtil.join(storeGoodsLabels.stream().map(StoreGoodsLabel::getLabelName).toArray(), ",")); } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index 3b9d18cc..fd25cf2b 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -365,9 +365,12 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { //关键字检索 if (CharSequenceUtil.isEmpty(searchDTO.getKeyword())) { List filterFunctionBuilders = new ArrayList<>(); - GaussDecayFunctionBuilder skuNoScore = ScoreFunctionBuilders.gaussDecayFunction("skuSource", 100, 10).setWeight(10); + GaussDecayFunctionBuilder skuNoScore = ScoreFunctionBuilders.gaussDecayFunction("skuSource", 50, 10, 50).setWeight(2); FunctionScoreQueryBuilder.FilterFunctionBuilder skuNoBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchAllQuery(), skuNoScore); filterFunctionBuilders.add(skuNoBuilder); + FieldValueFactorFunctionBuilder buyCountScore = ScoreFunctionBuilders.fieldValueFactorFunction("buyCount").modifier(FieldValueFactorFunction.Modifier.LOG1P).setWeight(3); + FunctionScoreQueryBuilder.FilterFunctionBuilder buyCountBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchAllQuery(), buyCountScore); + filterFunctionBuilders.add(buyCountBuilder); FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()]; filterFunctionBuilders.toArray(builders); FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders) @@ -561,7 +564,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.wildcardQuery(ATTR_VALUE, "*" + keyword + "*"), ScoreMode.None), ScoreFunctionBuilders.weightFactorFunction(8))); - GaussDecayFunctionBuilder skuNoScore = ScoreFunctionBuilders.gaussDecayFunction("skuSource", 100, 10).setWeight(7); + GaussDecayFunctionBuilder skuNoScore = ScoreFunctionBuilders.gaussDecayFunction("skuSource", 50, 10, 50).setWeight(7); FunctionScoreQueryBuilder.FilterFunctionBuilder skuNoBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(goodsNameQuery, skuNoScore); filterFunctionBuilders.add(skuNoBuilder); diff --git a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java index 2ecb8cdd..89d878b3 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java @@ -33,7 +33,7 @@ public class ElasticsearchController { } @GetMapping("/progress") - public ResultMessage> getProgress() { + public ResultMessage> getProgress() { return ResultUtil.data(esGoodsIndexService.getProgress()); } } diff --git a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java index 3ecf49f3..762bcbdb 100644 --- a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java +++ b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java @@ -3,9 +3,11 @@ package cn.lili.test.elasticsearch; import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; import cn.lili.common.vo.PageVO; +import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.service.PromotionService; import cn.lili.modules.search.entity.dos.EsGoodsAttribute; @@ -47,6 +49,9 @@ class EsTest { @Autowired private GoodsSkuService goodsSkuService; + @Autowired + private GoodsService goodsService; + @Autowired private Cache cache; @@ -63,6 +68,13 @@ class EsTest { // System.out.println(HtmlUtil.filter("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-")); // Date dt1 = new Date(2021, 12, 10); // Date dt2 = new Date(2021, 12, 14); + for (int i = 0; i < 1000; i++) { + + Goods goods = new Goods(); + goods.setGoodsName("测试商品" + i); +// goods.setAuthFlag(); + } + // } @@ -132,7 +144,7 @@ class EsTest { esGoodsIndices.add(index); cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity()); } - esGoodsIndexService.initIndex(esGoodsIndices); + esGoodsIndexService.initIndex(esGoodsIndices, true); Assertions.assertTrue(true); }