From 486bebe6d2ade36095ed6c50f96ad9543116ede6 Mon Sep 17 00:00:00 2001 From: xiaochangbai <704566072@qq.com> Date: Wed, 1 Jun 2022 18:03:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=E6=99=BA=E8=83=BD=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=A8=E8=8D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/entity/dto/EsGoodsSearchDTO.java | 3 ++ .../serviceimpl/EsGoodsSearchServiceImpl.java | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java index 564d0ecd..2f0759d6 100644 --- a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java +++ b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java @@ -44,4 +44,7 @@ public class EsGoodsSearchDTO { @ApiModelProperty(hidden = true) private Map> notShowCol = new HashMap<>(); + @ApiModelProperty("当前商品skuId,根据当前浏览的商品信息来给用户推荐可能喜欢的商品") + private String currentGoodsId; + } 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 620d3bd8..e77d5bce 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 @@ -363,6 +363,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { //对查询条件进行处理 this.commonSearch(filterBuilder, searchDTO); + //智能推荐 + this.recommended(filterBuilder,searchDTO); + //未上架的商品不显示 filterBuilder.must(QueryBuilders.matchQuery("marketEnable", GoodsStatusEnum.UPPER.name())); //待审核和审核不通过的商品不显示 @@ -401,6 +404,36 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { return nativeSearchQueryBuilder; } + /** + * 商品推荐 + * @param filterBuilder + * @param searchDTO + */ + private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) { + EsGoodsIndex currentGoodsIndice = null; + if(CharSequenceUtil.isNotEmpty(searchDTO.getCurrentGoodsId())){ + //查询当前商品的信息 + NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder(); + NativeSearchQuery build = searchQueryBuilder.build(); + build.setIds(Arrays.asList(searchDTO.getCurrentGoodsId())); + List esGoodsIndices = restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class)); + if(esGoodsIndices==null || esGoodsIndices.size()<1){ + return; + } + currentGoodsIndice = esGoodsIndices.get(0); + } + //推荐相同分类的商品 + String categoryPath = currentGoodsIndice.getCategoryPath(); + if(CharSequenceUtil.isNotEmpty(categoryPath)){ + //匹配二级分类 + String substring = categoryPath.substring(0, categoryPath.lastIndexOf(",")); + filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath",substring+"*")); + } + + //排除当前商品 + filterBuilder.mustNot(QueryBuilders.matchQuery("id",searchDTO.getCurrentGoodsId())); + } + /** * 查询属性处理 * From ccb57411a2f0ae224aafd87daa67bcf8467ea4ac Mon Sep 17 00:00:00 2001 From: xiaochangbai <704566072@qq.com> Date: Wed, 1 Jun 2022 21:27:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EsGoodsSearchServiceImpl.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 e77d5bce..e91bd477 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 @@ -410,28 +410,28 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { * @param searchDTO */ private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) { - EsGoodsIndex currentGoodsIndice = null; - if(CharSequenceUtil.isNotEmpty(searchDTO.getCurrentGoodsId())){ - //查询当前商品的信息 - NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder(); - NativeSearchQuery build = searchQueryBuilder.build(); - build.setIds(Arrays.asList(searchDTO.getCurrentGoodsId())); - List esGoodsIndices = restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class)); - if(esGoodsIndices==null || esGoodsIndices.size()<1){ - return; - } - currentGoodsIndice = esGoodsIndices.get(0); + + String currentGoodsId = searchDTO.getCurrentGoodsId(); + if(CharSequenceUtil.isEmpty(currentGoodsId)) { + return; } - //推荐相同分类的商品 - String categoryPath = currentGoodsIndice.getCategoryPath(); + + //排除当前商品 + filterBuilder.mustNot(QueryBuilders.matchQuery("id",currentGoodsId)); + + //查询当前浏览商品的索引信息 + EsGoodsIndex esGoodsIndex = restTemplate.get(currentGoodsId, EsGoodsIndex.class); + if(esGoodsIndex==null) { + return; + } + //推荐与当前浏览商品相同一个二级分类下的商品 + String categoryPath = esGoodsIndex.getCategoryPath(); if(CharSequenceUtil.isNotEmpty(categoryPath)){ //匹配二级分类 String substring = categoryPath.substring(0, categoryPath.lastIndexOf(",")); filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath",substring+"*")); } - //排除当前商品 - filterBuilder.mustNot(QueryBuilders.matchQuery("id",searchDTO.getCurrentGoodsId())); } /**