Authored by wangnan

【自定义标签】 品类+模糊搜索 聚合,筛选

1 package com.yoho.search.service.aggregations.impls; 1 package com.yoho.search.service.aggregations.impls;
2 2
3 -import java.util.Map;  
4 -  
5 -import org.springframework.beans.factory.annotation.Autowired;  
6 -import org.springframework.stereotype.Service;  
7 -  
8 import com.yoho.search.core.es.agg.IAggregation; 3 import com.yoho.search.core.es.agg.IAggregation;
9 -import com.yoho.search.service.base.index.BrandIndexBaseService;  
10 -import com.yoho.search.service.base.index.ColorIndexBaseService;  
11 -import com.yoho.search.service.base.index.ProductIndexBaseService;  
12 -import com.yoho.search.service.base.index.PromotionIndexBaseService;  
13 -import com.yoho.search.service.base.index.ShopsIndexBaseService;  
14 -import com.yoho.search.service.base.index.SizeIndexBaseService;  
15 -import com.yoho.search.service.base.index.StandardIndexBaseService;  
16 -import com.yoho.search.service.base.index.StyleIndexBaseService; 4 +import com.yoho.search.service.base.index.*;
17 import com.yoho.search.service.helper.SearchAfterCacheHelper; 5 import com.yoho.search.service.helper.SearchAfterCacheHelper;
18 import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch; 6 import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import java.util.Map;
19 11
20 @Service 12 @Service
21 public class AggregationFactoryService { 13 public class AggregationFactoryService {
@@ -40,6 +32,8 @@ public class AggregationFactoryService { @@ -40,6 +32,8 @@ public class AggregationFactoryService {
40 private PersonalVectorFeatureSearch personalVectorFeatureSearch; 32 private PersonalVectorFeatureSearch personalVectorFeatureSearch;
41 @Autowired 33 @Autowired
42 private ProductIndexBaseService productIndexBaseService; 34 private ProductIndexBaseService productIndexBaseService;
  35 + @Autowired
  36 + private CustomizeTagBaseService customizeTagBaseService;
43 37
44 public IAggregation getAgeLevelAggregation() { 38 public IAggregation getAgeLevelAggregation() {
45 return new AgeLevelAggregation(); 39 return new AgeLevelAggregation();
@@ -136,4 +130,7 @@ public class AggregationFactoryService { @@ -136,4 +130,7 @@ public class AggregationFactoryService {
136 public IAggregation getShopAggregation(int aggCount) { 130 public IAggregation getShopAggregation(int aggCount) {
137 return new ShopAggregation(shopsIndexBaseService, aggCount); 131 return new ShopAggregation(shopsIndexBaseService, aggCount);
138 } 132 }
  133 +
  134 + public IAggregation getCustomizeTagAggregation(){return new CustomizeTagAggregation(customizeTagBaseService);}
139 } 135 }
  136 +
  1 +package com.yoho.search.service.aggregations.impls;
  2 +
  3 +import com.yoho.search.base.utils.ProductIndexEsField;
  4 +import com.yoho.search.core.es.agg.AbstractAggregation;
  5 +import com.yoho.search.service.base.index.CustomizeTagBaseService;
  6 +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
  7 +import org.elasticsearch.search.aggregations.Aggregation;
  8 +import org.elasticsearch.search.aggregations.AggregationBuilders;
  9 +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +
  13 +import java.util.Iterator;
  14 +import java.util.LinkedHashSet;
  15 +import java.util.Map;
  16 +import java.util.Set;
  17 +
  18 +/**
  19 + * Created by wangnan on 2017/9/12.
  20 + */
  21 +public class CustomizeTagAggregation extends AbstractAggregation {
  22 +
  23 + private final Logger logger = LoggerFactory.getLogger(getClass());
  24 +
  25 + private CustomizeTagBaseService customizeTagBaseService;
  26 +
  27 + CustomizeTagAggregation(CustomizeTagBaseService colorIndexBaseService) {
  28 + this.customizeTagBaseService = colorIndexBaseService;
  29 + }
  30 +
  31 + @Override
  32 + public String aggName() {
  33 + return "customizeTagAgg";
  34 + }
  35 +
  36 + @Override
  37 + public String filterName() {
  38 + return "customize_tag";
  39 + }
  40 +
  41 + @Override
  42 + public AbstractAggregationBuilder<?> getBuilder() {
  43 + return AggregationBuilders.terms(aggName()).field(ProductIndexEsField.customizeTagId).size(100);
  44 + }
  45 +
  46 + @Override
  47 + public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
  48 + MultiBucketsAggregation aggregation = this.getAggregation(aggMaps);
  49 + if (aggregation == null) {
  50 + return null;
  51 + }
  52 + Set<String> tagIdSet = new LinkedHashSet<String>();
  53 + Iterator<? extends MultiBucketsAggregation.Bucket> itTagAgg = aggregation.getBuckets().iterator();
  54 + while (itTagAgg.hasNext()) {
  55 + MultiBucketsAggregation.Bucket ltTag = itTagAgg.next();
  56 + for (String tagId : ltTag.getKeyAsString().split(",")) {
  57 + tagIdSet.add(tagId);
  58 + }
  59 + }
  60 + try {
  61 + return customizeTagBaseService.getTagListByIds(tagIdSet);
  62 + } catch (Exception e) {
  63 + e.printStackTrace();
  64 + return null;
  65 + }
  66 + }
  67 +
  68 +}
@@ -6,7 +6,7 @@ public class SearchRequestParams { @@ -6,7 +6,7 @@ public class SearchRequestParams {
6 public static final String PARAM_SEARCH_PAGEID = "pageId"; // 页面id 6 public static final String PARAM_SEARCH_PAGEID = "pageId"; // 页面id
7 public static final String PARAM_SEARCH_VIEWNUM = "viewNum"; // 数量 7 public static final String PARAM_SEARCH_VIEWNUM = "viewNum"; // 数量
8 8
9 - public static final String PARAM_SEARCH_QUERY = "query";// 检索关键词 9 + public static final String PARAM_SEARCH_QUERY = "query";// 检索关键词
10 public static final String PARAM_SEARCH_SHOPS_KEYWORD = "keyword";// 店铺检索词 10 public static final String PARAM_SEARCH_SHOPS_KEYWORD = "keyword";// 店铺检索词
11 public static final String PARAM_SEARCH_GENDER = "gender"; // 性别ids[1,2,3] 11 public static final String PARAM_SEARCH_GENDER = "gender"; // 性别ids[1,2,3]
12 12
@@ -120,4 +120,6 @@ public class SearchRequestParams { @@ -120,4 +120,6 @@ public class SearchRequestParams {
120 public static final String SHOPS_PARAM_STATUS = "status"; 120 public static final String SHOPS_PARAM_STATUS = "status";
121 public static final String SHOPS_PARAM_ISGLOBAL = "isGlobal"; 121 public static final String SHOPS_PARAM_ISGLOBAL = "isGlobal";
122 122
  123 + public static final String SHOPS_PARAM_CUSTOMIZE_TAG = "customize_tag";
  124 +
123 } 125 }
  1 +package com.yoho.search.service.base.index;
  2 +
  3 +import com.yoho.search.base.utils.ISearchConstants;
  4 +import com.yoho.search.service.base.SearchCommonService;
  5 +import org.apache.commons.collections.MapUtils;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.*;
  12 +
  13 +/**
  14 + * Created by wangnan on 2017/9/12.
  15 + */
  16 +@Service
  17 +public class CustomizeTagBaseService {
  18 +
  19 + private final Logger logger = LoggerFactory.getLogger(getClass());
  20 + private static final String ACTIVITY_TAG_INDEX_NAME = ISearchConstants.INDEX_NAME_ACTIVITY_TAG;
  21 +
  22 + @Autowired
  23 + private SearchCommonService searchCommonService;
  24 +
  25 +
  26 + public List<Map<String, Object>> getTagListByIds(final Collection<?> tagIds) {
  27 + List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
  28 + try {
  29 + List<Map<String, Object>> sizeEsMapList = searchCommonService.doMultiGetCommon(ACTIVITY_TAG_INDEX_NAME, tagIds);
  30 + for (Map<String, Object> sizeEsMap : sizeEsMapList) {
  31 + resultList.add(this.getTagMap(sizeEsMap));
  32 + }
  33 + } catch (Exception e) {
  34 + logger.error(e.getMessage(), e);
  35 + }
  36 + return resultList;
  37 + }
  38 +
  39 + private Map<String, Object> getTagMap(Map<String, Object> esMap) {
  40 + Map<String, Object> map = new HashMap<String, Object>();
  41 + map.put("id", MapUtils.getIntValue(esMap, "id", 0));
  42 + map.put("name", MapUtils.getString(esMap, "activityName", ""));
  43 + return map;
  44 + }
  45 +}
1 package com.yoho.search.service.base.index; 1 package com.yoho.search.service.base.index;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.HashMap;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 -  
8 -import javax.annotation.PostConstruct;  
9 - 3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.yoho.search.base.utils.ProductIndexEsField;
10 import org.apache.commons.collections.MapUtils; 5 import org.apache.commons.collections.MapUtils;
11 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
12 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
14 9
15 -import com.alibaba.fastjson.JSONArray;  
16 -import com.yoho.search.base.utils.ProductIndexEsField; 10 +import javax.annotation.PostConstruct;
  11 +import java.util.ArrayList;
  12 +import java.util.HashMap;
  13 +import java.util.List;
  14 +import java.util.Map;
17 15
18 @Service 16 @Service
19 public class ProductIndexBaseService { 17 public class ProductIndexBaseService {
@@ -98,6 +96,9 @@ public class ProductIndexBaseService { @@ -98,6 +96,9 @@ public class ProductIndexBaseService {
98 productIndexIncludeFields.add(ProductIndexEsField.tblBrandId); 96 productIndexIncludeFields.add(ProductIndexEsField.tblBrandId);
99 productIndexIncludeFields.add(ProductIndexEsField.tblCountryId); 97 productIndexIncludeFields.add(ProductIndexEsField.tblCountryId);
100 productIndexIncludeFields.add(ProductIndexEsField.tblCountryName); 98 productIndexIncludeFields.add(ProductIndexEsField.tblCountryName);
  99 +
  100 + productIndexIncludeFields.add(ProductIndexEsField.customizeTag);
  101 + productIndexIncludeFields.add(ProductIndexEsField.promotionTag);
101 } 102 }
102 103
103 public List<String> getProductIndexIncludeFields() { 104 public List<String> getProductIndexIncludeFields() {
@@ -196,6 +197,11 @@ public class ProductIndexBaseService { @@ -196,6 +197,11 @@ public class ProductIndexBaseService {
196 productMap.put("tbl_brand_id", MapUtils.getIntValue(map, ProductIndexEsField.tblBrandId, 0)); 197 productMap.put("tbl_brand_id", MapUtils.getIntValue(map, ProductIndexEsField.tblBrandId, 0));
197 productMap.put("tbl_country_name", MapUtils.getString(map, ProductIndexEsField.tblCountryName, "")); 198 productMap.put("tbl_country_name", MapUtils.getString(map, ProductIndexEsField.tblCountryName, ""));
198 productMap.put("tbl_plane", (tbl_country_id > 0 && tbl_country_id != 86) ? "Y" : "N"); 199 productMap.put("tbl_plane", (tbl_country_id > 0 && tbl_country_id != 86) ? "Y" : "N");
  200 +
  201 + //标签
  202 + productMap.put("customize_tag", MapUtils.getObject(map, ProductIndexEsField.customizeTag, new JSONArray()));
  203 + productMap.put("promotion_tag", MapUtils.getObject(map, ProductIndexEsField.promotionTag, new JSONArray()));
  204 +
199 return productMap; 205 return productMap;
200 } 206 }
201 207
1 package com.yoho.search.service.helper; 1 package com.yoho.search.service.helper;
2 2
3 -import java.util.Arrays;  
4 -import java.util.Date;  
5 -import java.util.Iterator;  
6 -import java.util.List;  
7 -import java.util.Map;  
8 -  
9 -import org.apache.commons.lang.StringUtils;  
10 -import org.apache.lucene.search.join.ScoreMode;  
11 -import org.elasticsearch.index.query.BoolQueryBuilder;  
12 -import org.elasticsearch.index.query.MultiMatchQueryBuilder;  
13 -import org.elasticsearch.index.query.Operator;  
14 -import org.elasticsearch.index.query.QueryBuilder;  
15 -import org.elasticsearch.index.query.QueryBuilders;  
16 -import org.elasticsearch.index.query.RangeQueryBuilder;  
17 -import org.slf4j.Logger;  
18 -import org.slf4j.LoggerFactory;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.stereotype.Service;  
21 -  
22 import com.yoho.search.base.constants.ProductModelValueConstants; 3 import com.yoho.search.base.constants.ProductModelValueConstants;
23 import com.yoho.search.base.utils.ConvertUtils; 4 import com.yoho.search.base.utils.ConvertUtils;
24 import com.yoho.search.base.utils.DateUtil; 5 import com.yoho.search.base.utils.DateUtil;
@@ -26,6 +7,15 @@ import com.yoho.search.base.utils.ISearchConstants; @@ -26,6 +7,15 @@ import com.yoho.search.base.utils.ISearchConstants;
26 import com.yoho.search.base.utils.ProductIndexEsField; 7 import com.yoho.search.base.utils.ProductIndexEsField;
27 import com.yoho.search.common.utils.SearchKeyWordUtils; 8 import com.yoho.search.common.utils.SearchKeyWordUtils;
28 import com.yoho.search.service.base.SearchRequestParams; 9 import com.yoho.search.service.base.SearchRequestParams;
  10 +import org.apache.commons.lang.StringUtils;
  11 +import org.apache.lucene.search.join.ScoreMode;
  12 +import org.elasticsearch.index.query.*;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Service;
  17 +
  18 +import java.util.*;
29 19
30 @Service 20 @Service
31 public class SearchServiceHelper { 21 public class SearchServiceHelper {
@@ -224,6 +214,11 @@ public class SearchServiceHelper { @@ -224,6 +214,11 @@ public class SearchServiceHelper {
224 int[] storeShowStatuss = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STORESHOWSTATUS), ","); 214 int[] storeShowStatuss = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STORESHOWSTATUS), ",");
225 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, storeShowStatuss)); 215 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, storeShowStatuss));
226 } 216 }
  217 + //个性化标签
  218 + if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
  219 + int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
  220 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagId, ids));
  221 + }
227 // //////////////////////////////////////////不支持多个参数/////////////////////////////////////////////////////////// 222 // //////////////////////////////////////////不支持多个参数///////////////////////////////////////////////////////////
228 // 是否特价 223 // 是否特价
229 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) { 224 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) {
1 package com.yoho.search.service.scene; 1 package com.yoho.search.service.scene;
2 2
3 -import java.util.Map;  
4 -  
5 -import org.apache.commons.lang.StringUtils;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Service;  
10 -  
11 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
12 import com.yoho.search.base.utils.SearchPageIdDefine; 4 import com.yoho.search.base.utils.SearchPageIdDefine;
13 import com.yoho.search.common.utils.SearchApiResultUtils; 5 import com.yoho.search.common.utils.SearchApiResultUtils;
@@ -19,7 +11,18 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; @@ -19,7 +11,18 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
19 import com.yoho.search.service.scene.common.AbstractSceneService; 11 import com.yoho.search.service.scene.common.AbstractSceneService;
20 import com.yoho.search.service.scene.common.SceneProductListService; 12 import com.yoho.search.service.scene.common.SceneProductListService;
21 import com.yoho.search.service.scene.common.SceneSelectionsService; 13 import com.yoho.search.service.scene.common.SceneSelectionsService;
  14 +import com.yoho.search.service.service.IProductIndexService;
22 import com.yoho.search.service.service.ISearchRecommendService; 15 import com.yoho.search.service.service.ISearchRecommendService;
  16 +import org.apache.commons.lang.StringUtils;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.util.Map;
  23 +import java.util.concurrent.CompletableFuture;
  24 +import java.util.concurrent.ExecutorService;
  25 +import java.util.concurrent.Executors;
23 26
24 @Service 27 @Service
25 public class FuzzySceneService extends AbstractSceneService { 28 public class FuzzySceneService extends AbstractSceneService {
@@ -38,6 +41,10 @@ public class FuzzySceneService extends AbstractSceneService { @@ -38,6 +41,10 @@ public class FuzzySceneService extends AbstractSceneService {
38 private SearchDynamicConfigService searchDynamicConfigService; 41 private SearchDynamicConfigService searchDynamicConfigService;
39 @Autowired 42 @Autowired
40 private SearchKeyWordHelper searchKeyWordService; 43 private SearchKeyWordHelper searchKeyWordService;
  44 + @Autowired
  45 + private IProductIndexService productIndexService;
  46 +
  47 + private ExecutorService executorService = Executors.newFixedThreadPool(100);
41 48
42 // 当少于20个商品时 返回智能搜索词提示 49 // 当少于20个商品时 返回智能搜索词提示
43 private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; 50 private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20;
@@ -62,22 +69,29 @@ public class FuzzySceneService extends AbstractSceneService { @@ -62,22 +69,29 @@ public class FuzzySceneService extends AbstractSceneService {
62 @Override 69 @Override
63 public SearchApiResult productList(Map<String, String> paramMap) { 70 public SearchApiResult productList(Map<String, String> paramMap) {
64 try { 71 try {
65 - // 0、参数校验 72 + // 1、参数校验
66 if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) { 73 if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
67 return new SearchApiResult().setCode(400).setMessage("请传query参数"); 74 return new SearchApiResult().setCode(400).setMessage("请传query参数");
68 } 75 }
69 - // 1、添加默认参数 76 + // 2、添加默认参数
70 this.addParamsToParamMap(paramMap); 77 this.addParamsToParamMap(paramMap);
71 - // 2、获取商品列表 78 + // 3、获取商品列表
72 SearchApiResult searchApiResult = sceneProductListService.productList(paramMap); 79 SearchApiResult searchApiResult = sceneProductListService.productList(paramMap);
73 - // 3、加入建议词 80 + // 4、加入建议词
74 this.addSuggestion(searchApiResult, paramMap); 81 this.addSuggestion(searchApiResult, paramMap);
75 - // 4、模糊搜索页记录关键字对应的查询结果 82 + // 5、模糊搜索页记录关键字对应的查询结果
76 String queryWord = paramMap.get("query"); 83 String queryWord = paramMap.get("query");
77 if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) { 84 if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
78 long total = ((JSONObject) searchApiResult.getData()).getLongValue("total"); 85 long total = ((JSONObject) searchApiResult.getData()).getLongValue("total");
79 searchKeyWordService.recordKeyWordByResultCount(queryWord, total); 86 searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
80 } 87 }
  88 + // 6、获取自定义标签聚合结果
  89 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> {
  90 + return productIndexService.aggCustomizeTag(paramMap);
  91 + }, executorService);
  92 + SearchApiResult customizeTags = customizeTagFuture.get();
  93 + JSONObject dataMap = (JSONObject)searchApiResult.getData();
  94 + dataMap.put("customize_tag", customizeTags.getData());
81 return searchApiResult; 95 return searchApiResult;
82 } catch (Exception e) { 96 } catch (Exception e) {
83 logger.error(e.getMessage(), e); 97 logger.error(e.getMessage(), e);
1 package com.yoho.search.service.scene; 1 package com.yoho.search.service.scene;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.Iterator;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 -import java.util.concurrent.CompletableFuture;  
8 -import java.util.concurrent.ExecutorService;  
9 -import java.util.concurrent.Executors;  
10 -  
11 -import org.apache.commons.collections.MapUtils;  
12 -import org.apache.commons.lang.StringUtils;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.beans.factory.annotation.Autowired;  
16 -import org.springframework.stereotype.Service;  
17 -  
18 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
19 import com.yoho.search.base.utils.SearchPageIdDefine; 4 import com.yoho.search.base.utils.SearchPageIdDefine;
20 import com.yoho.search.models.SearchApiResult; 5 import com.yoho.search.models.SearchApiResult;
@@ -25,6 +10,20 @@ import com.yoho.search.service.scene.common.AbstractSceneService; @@ -25,6 +10,20 @@ import com.yoho.search.service.scene.common.AbstractSceneService;
25 import com.yoho.search.service.scene.common.SceneProductListService; 10 import com.yoho.search.service.scene.common.SceneProductListService;
26 import com.yoho.search.service.scene.common.SceneSelectionsService; 11 import com.yoho.search.service.scene.common.SceneSelectionsService;
27 import com.yoho.search.service.service.IProductIndexService; 12 import com.yoho.search.service.service.IProductIndexService;
  13 +import org.apache.commons.collections.MapUtils;
  14 +import org.apache.commons.lang.StringUtils;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.stereotype.Service;
  19 +
  20 +import java.util.ArrayList;
  21 +import java.util.Iterator;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +import java.util.concurrent.CompletableFuture;
  25 +import java.util.concurrent.ExecutorService;
  26 +import java.util.concurrent.Executors;
28 27
29 @Service 28 @Service
30 public class SortSceneService extends AbstractSceneService { 29 public class SortSceneService extends AbstractSceneService {
@@ -94,15 +93,20 @@ public class SortSceneService extends AbstractSceneService { @@ -94,15 +93,20 @@ public class SortSceneService extends AbstractSceneService {
94 return null; 93 return null;
95 } 94 }
96 }, executorService); 95 }, executorService);
97 - // 3、获取规则的聚合结果 96 + // 3、获取规则和自定义标签的聚合结果
98 CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> { 97 CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> {
99 return productIndexService.aggStandard(paramMap); 98 return productIndexService.aggStandard(paramMap);
100 }, executorService); 99 }, executorService);
  100 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> {
  101 + return productIndexService.aggCustomizeTag(paramMap);
  102 + }, executorService);
101 // 4、组合结果 103 // 4、组合结果
102 SearchApiResult productList = productListFuture.get(); 104 SearchApiResult productList = productListFuture.get();
103 SearchApiResult standards = standardsFuture.get(); 105 SearchApiResult standards = standardsFuture.get();
  106 + SearchApiResult customizeTags = customizeTagFuture.get();
104 JSONObject jsonObject = (JSONObject) productList.getData(); 107 JSONObject jsonObject = (JSONObject) productList.getData();
105 jsonObject.put("standard", standards.getData()); 108 jsonObject.put("standard", standards.getData());
  109 + jsonObject.put("customize_tag", customizeTags.getData());
106 return productList; 110 return productList;
107 } catch (Exception e) { 111 } catch (Exception e) {
108 logger.error(e.getMessage(), e); 112 logger.error(e.getMessage(), e);
1 package com.yoho.search.service.scene.common; 1 package com.yoho.search.service.scene.common;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.HashMap;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 -import java.util.concurrent.CompletableFuture;  
8 -import java.util.concurrent.ExecutorService;  
9 -import java.util.concurrent.Executors;  
10 -  
11 -import org.elasticsearch.index.query.BoolQueryBuilder;  
12 -import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;  
13 -import org.elasticsearch.search.aggregations.Aggregation;  
14 -import org.slf4j.Logger;  
15 -import org.slf4j.LoggerFactory;  
16 -import org.springframework.beans.factory.annotation.Autowired;  
17 -import org.springframework.stereotype.Service;  
18 -  
19 import com.alibaba.fastjson.JSONArray; 3 import com.alibaba.fastjson.JSONArray;
20 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
21 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
@@ -29,6 +13,21 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService; @@ -29,6 +13,21 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
29 import com.yoho.search.service.base.SearchCommonService; 13 import com.yoho.search.service.base.SearchCommonService;
30 import com.yoho.search.service.helper.SearchParamHelper; 14 import com.yoho.search.service.helper.SearchParamHelper;
31 import com.yoho.search.service.service.IAggRecommendService; 15 import com.yoho.search.service.service.IAggRecommendService;
  16 +import org.elasticsearch.index.query.BoolQueryBuilder;
  17 +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
  18 +import org.elasticsearch.search.aggregations.Aggregation;
  19 +import org.slf4j.Logger;
  20 +import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.stereotype.Service;
  23 +
  24 +import java.util.ArrayList;
  25 +import java.util.HashMap;
  26 +import java.util.List;
  27 +import java.util.Map;
  28 +import java.util.concurrent.CompletableFuture;
  29 +import java.util.concurrent.ExecutorService;
  30 +import java.util.concurrent.Executors;
32 31
33 @Service 32 @Service
34 public class SceneSelectionsService extends AbstractCacheAbleService { 33 public class SceneSelectionsService extends AbstractCacheAbleService {
1 package com.yoho.search.service.service; 1 package com.yoho.search.service.service;
2 2
3 -import java.util.Arrays;  
4 -import java.util.Map;  
5 -  
6 -import javax.annotation.PostConstruct;  
7 -  
8 -import org.elasticsearch.search.aggregations.Aggregation;  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import org.springframework.beans.factory.annotation.Autowired;  
12 -import org.springframework.context.ApplicationEventPublisher;  
13 -import org.springframework.context.ApplicationEventPublisherAware;  
14 -import org.springframework.stereotype.Service;  
15 -  
16 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
17 import com.yoho.error.event.SearchEvent; 4 import com.yoho.error.event.SearchEvent;
18 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
@@ -28,6 +15,17 @@ import com.yoho.search.service.base.SearchCacheService; @@ -28,6 +15,17 @@ import com.yoho.search.service.base.SearchCacheService;
28 import com.yoho.search.service.base.SearchCommonService; 15 import com.yoho.search.service.base.SearchCommonService;
29 import com.yoho.search.service.base.SearchRequestParams; 16 import com.yoho.search.service.base.SearchRequestParams;
30 import com.yoho.search.service.helper.SearchParamHelper; 17 import com.yoho.search.service.helper.SearchParamHelper;
  18 +import org.elasticsearch.search.aggregations.Aggregation;
  19 +import org.slf4j.Logger;
  20 +import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.context.ApplicationEventPublisher;
  23 +import org.springframework.context.ApplicationEventPublisherAware;
  24 +import org.springframework.stereotype.Service;
  25 +
  26 +import javax.annotation.PostConstruct;
  27 +import java.util.Arrays;
  28 +import java.util.Map;
31 29
32 @Service 30 @Service
33 public class AggregationService implements ApplicationEventPublisherAware { 31 public class AggregationService implements ApplicationEventPublisherAware {
@@ -262,4 +260,14 @@ public class AggregationService implements ApplicationEventPublisherAware { @@ -262,4 +260,14 @@ public class AggregationService implements ApplicationEventPublisherAware {
262 return this.getAggNameAndResponseWithCache(standardAggregation, searchParam); 260 return this.getAggNameAndResponseWithCache(standardAggregation, searchParam);
263 } 261 }
264 262
  263 + /**
  264 + * 获取自定义标签的聚合结果
  265 + */
  266 + public JSONObject getCustomizeTagResult(Map<String, String> paramMap) throws Exception {
  267 + IAggregation customizeAggregation = aggregationFactoryService.getCustomizeTagAggregation();
  268 + String filterParamName = null;
  269 + SearchParam searchParam = this.genSearchParamForAgg(customizeAggregation, paramMap, filterParamName, 0);
  270 + return this.getAggNameAndResponseWithCache(customizeAggregation, searchParam);
  271 + }
  272 +
265 } 273 }
@@ -8,75 +8,75 @@ public interface IProductIndexService { @@ -8,75 +8,75 @@ public interface IProductIndexService {
8 8
9 /** 9 /**
10 * 获取年龄层面的聚合结果 10 * 获取年龄层面的聚合结果
11 - * 11 + *
12 * @param paramMap 12 * @param paramMap
13 * @return 13 * @return
14 */ 14 */
15 public SearchApiResult aggAgeLevel(Map<String, String> paramMap); 15 public SearchApiResult aggAgeLevel(Map<String, String> paramMap);
16 - 16 +
17 /** 17 /**
18 * 获取性别层面的聚合结果 18 * 获取性别层面的聚合结果
19 * @param paramMap 19 * @param paramMap
20 * @return 20 * @return
21 */ 21 */
22 public SearchApiResult aggGender(Map<String, String> paramMap); 22 public SearchApiResult aggGender(Map<String, String> paramMap);
23 - 23 +
24 /** 24 /**
25 * 获取价格层面的聚合结果 25 * 获取价格层面的聚合结果
26 * @param paramMap 26 * @param paramMap
27 * @return 27 * @return
28 */ 28 */
29 public SearchApiResult aggPrice(Map<String, String> paramMap); 29 public SearchApiResult aggPrice(Map<String, String> paramMap);
30 - 30 +
31 /** 31 /**
32 * 获取颜色层面的聚合结果 32 * 获取颜色层面的聚合结果
33 * @param paramMap 33 * @param paramMap
34 * @return 34 * @return
35 */ 35 */
36 public SearchApiResult aggColor(Map<String, String> paramMap); 36 public SearchApiResult aggColor(Map<String, String> paramMap);
37 - 37 +
38 /** 38 /**
39 * 获取风格层面的聚合结果 39 * 获取风格层面的聚合结果
40 * @param paramMap 40 * @param paramMap
41 * @return 41 * @return
42 */ 42 */
43 public SearchApiResult aggStyle(Map<String, String> paramMap); 43 public SearchApiResult aggStyle(Map<String, String> paramMap);
44 - 44 +
45 /** 45 /**
46 * 获取品牌的聚合结果 46 * 获取品牌的聚合结果
47 * @param paramMap 47 * @param paramMap
48 * @return 48 * @return
49 */ 49 */
50 public SearchApiResult aggBrand(Map<String, String> paramMap); 50 public SearchApiResult aggBrand(Map<String, String> paramMap);
51 - 51 +
52 /** 52 /**
53 * 获取标准的聚合结果 53 * 获取标准的聚合结果
54 * @param paramMap 54 * @param paramMap
55 * @return 55 * @return
56 */ 56 */
57 public SearchApiResult aggStandard(Map<String, String> paramMap); 57 public SearchApiResult aggStandard(Map<String, String> paramMap);
58 - 58 +
59 /** 59 /**
60 * 获取尺码的聚合结果 60 * 获取尺码的聚合结果
61 * @param paramMap 61 * @param paramMap
62 * @return 62 * @return
63 */ 63 */
64 public SearchApiResult aggSize(Map<String, String> paramMap); 64 public SearchApiResult aggSize(Map<String, String> paramMap);
65 - 65 +
66 /** 66 /**
67 * 是否新品的聚合结果 67 * 是否新品的聚合结果
68 * @param paramMap 68 * @param paramMap
69 * @return 69 * @return
70 */ 70 */
71 public SearchApiResult aggNew(Map<String, String> paramMap); 71 public SearchApiResult aggNew(Map<String, String> paramMap);
72 - 72 +
73 /** 73 /**
74 * 是否限量的聚合结果 74 * 是否限量的聚合结果
75 * @param paramMap 75 * @param paramMap
76 * @return 76 * @return
77 */ 77 */
78 public SearchApiResult aggLimited(Map<String, String> paramMap); 78 public SearchApiResult aggLimited(Map<String, String> paramMap);
79 - 79 +
80 /** 80 /**
81 * 是否促销的聚合结果 81 * 是否促销的聚合结果
82 * @param paramMap 82 * @param paramMap
@@ -99,5 +99,18 @@ public interface IProductIndexService { @@ -99,5 +99,18 @@ public interface IProductIndexService {
99 */ 99 */
100 SearchApiResult aggKeywords(Map<String, String> paramMap); 100 SearchApiResult aggKeywords(Map<String, String> paramMap);
101 101
  102 + /**
  103 + * 店铺
  104 + * @param paramMap
  105 + * @return
  106 + */
102 SearchApiResult aggShops(Map<String, String> paramMap); 107 SearchApiResult aggShops(Map<String, String> paramMap);
  108 +
  109 +
  110 + /**
  111 + * 自定义标签
  112 + * @param paramMap
  113 + * @return
  114 + */
  115 + SearchApiResult aggCustomizeTag(Map<String, String> paramMap);
103 } 116 }
1 package com.yoho.search.service.service.impl; 1 package com.yoho.search.service.service.impl;
2 2
3 -import java.util.List;  
4 -import java.util.Map;  
5 -import java.util.Random;  
6 -import java.util.stream.Collectors;  
7 -  
8 -import org.apache.commons.lang.StringUtils;  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import org.springframework.beans.factory.annotation.Autowired;  
12 -import org.springframework.context.ApplicationEventPublisher;  
13 -import org.springframework.context.ApplicationEventPublisherAware;  
14 -import org.springframework.stereotype.Service;  
15 -  
16 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
17 import com.yoho.error.event.SearchEvent; 4 import com.yoho.error.event.SearchEvent;
18 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
@@ -22,6 +9,18 @@ import com.yoho.search.models.SearchApiResult; @@ -22,6 +9,18 @@ import com.yoho.search.models.SearchApiResult;
22 import com.yoho.search.service.base.SearchCommonService; 9 import com.yoho.search.service.base.SearchCommonService;
23 import com.yoho.search.service.service.AggregationService; 10 import com.yoho.search.service.service.AggregationService;
24 import com.yoho.search.service.service.IProductIndexService; 11 import com.yoho.search.service.service.IProductIndexService;
  12 +import org.apache.commons.lang.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.context.ApplicationEventPublisher;
  17 +import org.springframework.context.ApplicationEventPublisherAware;
  18 +import org.springframework.stereotype.Service;
  19 +
  20 +import java.util.List;
  21 +import java.util.Map;
  22 +import java.util.Random;
  23 +import java.util.stream.Collectors;
25 24
26 @Service 25 @Service
27 public class ProductIndexServiceImpl implements IProductIndexService, ApplicationEventPublisherAware { 26 public class ProductIndexServiceImpl implements IProductIndexService, ApplicationEventPublisherAware {
@@ -188,7 +187,8 @@ public class ProductIndexServiceImpl implements IProductIndexService, Applicatio @@ -188,7 +187,8 @@ public class ProductIndexServiceImpl implements IProductIndexService, Applicatio
188 }); 187 });
189 } 188 }
190 189
191 - @Override 190 +
  191 + @Override
192 public SearchApiResult aggNew(Map<String, String> paramMap) { 192 public SearchApiResult aggNew(Map<String, String> paramMap) {
193 return this.getSearchApiResult("aggNew", paramMap, new Searcher() { 193 return this.getSearchApiResult("aggNew", paramMap, new Searcher() {
194 @Override 194 @Override
@@ -256,4 +256,16 @@ public class ProductIndexServiceImpl implements IProductIndexService, Applicatio @@ -256,4 +256,16 @@ public class ProductIndexServiceImpl implements IProductIndexService, Applicatio
256 } 256 }
257 return new Random().ints(0, keywordList.size()).distinct().limit(randomKeywordCount).mapToObj(index -> keywordList.get(index)).collect(Collectors.toList()); 257 return new Random().ints(0, keywordList.size()).distinct().limit(randomKeywordCount).mapToObj(index -> keywordList.get(index)).collect(Collectors.toList());
258 } 258 }
  259 +
  260 +
  261 + @Override
  262 + public SearchApiResult aggCustomizeTag(Map<String, String> paramMap) {
  263 + return this.getSearchApiResult("aggCustomizeTag", paramMap, new Searcher() {
  264 + @Override
  265 + public Object getResult() throws Exception {
  266 + JSONObject jsonObject = aggregationService.getCustomizeTagResult(paramMap);
  267 + return jsonObject.get("customizeTagAgg");
  268 + }
  269 + });
  270 + }
259 } 271 }