Merge branch 'wn_customize_tag'
Showing
14 changed files
with
630 additions
and
277 deletions
@@ -133,6 +133,7 @@ public class SearchRequestParams { | @@ -133,6 +133,7 @@ public class SearchRequestParams { | ||
133 | 133 | ||
134 | 134 | ||
135 | public static final String SHOPS_PARAM_CUSTOMIZE_TAG = "customize_tag"; | 135 | public static final String SHOPS_PARAM_CUSTOMIZE_TAG = "customize_tag"; |
136 | + public static final String SHOPS_PARAM_CUSTOMIZE_TAG_NEW = "customize_tag_new"; | ||
136 | 137 | ||
137 | //Promotion index field | 138 | //Promotion index field |
138 | public static final String PROMOTIONINDEX_ISDEL = "isDel"; | 139 | public static final String PROMOTIONINDEX_ISDEL = "isDel"; |
service/src/main/java/com/yoho/search/service/aggregations/impls/ActivityTagAggregation.java
0 → 100644
1 | +package com.yoho.search.service.aggregations.impls; | ||
2 | + | ||
3 | +import com.yoho.search.base.utils.ConvertUtils; | ||
4 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
5 | +import com.yoho.search.common.SearchRequestParams; | ||
6 | +import com.yoho.search.core.es.agg.AbstractAggregation; | ||
7 | +import com.yoho.search.service.index.ActivityTagBaseService; | ||
8 | +import org.elasticsearch.index.query.BoolQueryBuilder; | ||
9 | +import org.elasticsearch.index.query.QueryBuilders; | ||
10 | +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
11 | +import org.elasticsearch.search.aggregations.Aggregation; | ||
12 | +import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
13 | +import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; | ||
14 | +import org.elasticsearch.search.aggregations.bucket.nested.InternalNested; | ||
15 | +import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder; | ||
16 | +import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; | ||
17 | +import org.elasticsearch.search.aggregations.bucket.terms.Terms; | ||
18 | +import org.springframework.util.CollectionUtils; | ||
19 | + | ||
20 | +import java.util.ArrayList; | ||
21 | +import java.util.List; | ||
22 | +import java.util.Map; | ||
23 | +import java.util.Set; | ||
24 | +import java.util.stream.Collectors; | ||
25 | + | ||
26 | +/** | ||
27 | + * Created by wangnan on 2017/9/12. | ||
28 | + */ | ||
29 | +public class ActivityTagAggregation extends AbstractAggregation { | ||
30 | + | ||
31 | + private Map<String, String> paramMap; | ||
32 | + private static String NESTED_PATH = ProductIndexEsField.customizeTags; | ||
33 | + private static String SUB_AGG_NAME = "subCustomizeTagAgg"; | ||
34 | + private static int AGG_COUNT = 100; | ||
35 | + private ActivityTagBaseService activityTagBaseService; | ||
36 | + | ||
37 | + ActivityTagAggregation(ActivityTagBaseService activityTagBaseService, Map<String, String> paramMap) { | ||
38 | + this.paramMap = paramMap; | ||
39 | + this.activityTagBaseService = activityTagBaseService; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public String aggName() { | ||
44 | + return "customizeTagAgg"; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public String filterName() { | ||
49 | + return "customizeTagFilter"; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public AbstractAggregationBuilder<?> getBuilder() { | ||
54 | + BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); | ||
55 | + if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) { | ||
56 | + int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ","); | ||
57 | + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids)); | ||
58 | + } | ||
59 | + AbstractAggregationBuilder<NestedAggregationBuilder> nestedAggregationBuilder = AggregationBuilders.nested(aggName(), NESTED_PATH) | ||
60 | + .subAggregation(AggregationBuilders.filter(filterName(), boolFilter) | ||
61 | + .subAggregation(AggregationBuilders.terms(SUB_AGG_NAME).field(ProductIndexEsField.customizeTagsId).size(AGG_COUNT).order(Terms.Order.count(false)))); | ||
62 | + return nestedAggregationBuilder; | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { | ||
67 | + InternalNested aggregation = (InternalNested) aggMaps.get(aggName()); | ||
68 | + if (CollectionUtils.isEmpty(aggregation.getAggregations().asList())) { | ||
69 | + return new ArrayList<>(); | ||
70 | + } | ||
71 | + InternalFilter filter = (InternalFilter) aggregation.getAggregations().asList().get(0); | ||
72 | + List<LongTerms.Bucket> longTerms = ((LongTerms) filter.getAggregations().asList().get(0)).getBucketsInternal(); | ||
73 | + Set<String> tagIdSet = longTerms.stream().map(e -> e.getKeyAsNumber().intValue() + "").collect(Collectors.toSet()); | ||
74 | + if (CollectionUtils.isEmpty(tagIdSet)) { | ||
75 | + return new ArrayList<>(); | ||
76 | + } | ||
77 | + return activityTagBaseService.getTagListByIds(tagIdSet); | ||
78 | + } | ||
79 | +} |
@@ -35,7 +35,9 @@ public class AggregationFactory { | @@ -35,7 +35,9 @@ public class AggregationFactory { | ||
35 | @Autowired | 35 | @Autowired |
36 | private ProductIndexBaseService productIndexBaseService; | 36 | private ProductIndexBaseService productIndexBaseService; |
37 | @Autowired | 37 | @Autowired |
38 | - private CustomizeTagBaseService customizeTagBaseService; | 38 | + private ActivityTagBaseService activityTagBaseService; |
39 | + @Autowired | ||
40 | + private CustomizeTagBaseService customizeTagBaseService; | ||
39 | @Autowired | 41 | @Autowired |
40 | private PromotionIndexBaseService promotionIndexBaseService; | 42 | private PromotionIndexBaseService promotionIndexBaseService; |
41 | @Autowired | 43 | @Autowired |
@@ -145,10 +147,14 @@ public class AggregationFactory { | @@ -145,10 +147,14 @@ public class AggregationFactory { | ||
145 | return new ShopAggregation(shopsIndexBaseService, aggCount); | 147 | return new ShopAggregation(shopsIndexBaseService, aggCount); |
146 | } | 148 | } |
147 | 149 | ||
148 | - public IAggregation getCustomizeTagAggregation(Map<String, String> paramMap) { | ||
149 | - return new CustomizeTagAggregation(customizeTagBaseService, paramMap); | 150 | + public IAggregation getActivityTagAggregation(Map<String, String> paramMap) { |
151 | + return new ActivityTagAggregation(activityTagBaseService, paramMap); | ||
150 | } | 152 | } |
151 | 153 | ||
154 | + public IAggregation getCustomizeTagAggregation(Map<String, String> paramMap) { | ||
155 | + return new CustomizeTagAggregation(customizeTagBaseService, paramMap); | ||
156 | + } | ||
157 | + | ||
152 | public IAggregation getShopAndSknAggregation(int aggCount) { | 158 | public IAggregation getShopAndSknAggregation(int aggCount) { |
153 | return new ShopAndSknAggregation(aggCount); | 159 | return new ShopAndSknAggregation(aggCount); |
154 | } | 160 | } |
1 | -package com.yoho.search.service.aggregations.impls; | ||
2 | - | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.List; | ||
5 | -import java.util.Map; | ||
6 | -import java.util.Set; | ||
7 | -import java.util.stream.Collectors; | ||
8 | - | ||
9 | -import org.elasticsearch.index.query.BoolQueryBuilder; | ||
10 | -import org.elasticsearch.index.query.QueryBuilders; | ||
11 | -import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
12 | -import org.elasticsearch.search.aggregations.Aggregation; | ||
13 | -import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
14 | -import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; | ||
15 | -import org.elasticsearch.search.aggregations.bucket.nested.InternalNested; | ||
16 | -import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder; | ||
17 | -import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; | ||
18 | -import org.elasticsearch.search.aggregations.bucket.terms.Terms; | ||
19 | -import org.springframework.util.CollectionUtils; | ||
20 | - | ||
21 | -import com.yoho.search.base.utils.ConvertUtils; | ||
22 | -import com.yoho.search.base.utils.ProductIndexEsField; | ||
23 | -import com.yoho.search.core.es.agg.AbstractAggregation; | ||
24 | -import com.yoho.search.common.SearchRequestParams; | ||
25 | -import com.yoho.search.service.index.CustomizeTagBaseService; | ||
26 | - | ||
27 | -/** | ||
28 | - * Created by wangnan on 2017/9/12. | ||
29 | - */ | ||
30 | -public class CustomizeTagAggregation extends AbstractAggregation { | ||
31 | - | ||
32 | - private Map<String, String> paramMap; | ||
33 | - private static String NESTED_PATH = ProductIndexEsField.customizeTags; | ||
34 | - private static String SUB_AGG_NAME = "subCustomizeTagAgg"; | ||
35 | - private static int AGG_COUNT = 100; | ||
36 | - private CustomizeTagBaseService customizeTagBaseService; | ||
37 | - | ||
38 | - CustomizeTagAggregation(CustomizeTagBaseService colorIndexBaseService, Map<String, String> paramMap) { | ||
39 | - this.paramMap = paramMap; | ||
40 | - this.customizeTagBaseService = colorIndexBaseService; | ||
41 | - } | ||
42 | - | ||
43 | - @Override | ||
44 | - public String aggName() { | ||
45 | - return "customizeTagAgg"; | ||
46 | - } | ||
47 | - | ||
48 | - @Override | ||
49 | - public String filterName() { | ||
50 | - return "customizeTagFilter"; | ||
51 | - } | ||
52 | - | ||
53 | - @Override | ||
54 | - public AbstractAggregationBuilder<?> getBuilder() { | ||
55 | - BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); | ||
56 | - if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) { | ||
57 | - int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ","); | ||
58 | - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids)); | ||
59 | - } | ||
60 | - AbstractAggregationBuilder<NestedAggregationBuilder> nestedAggregationBuilder = AggregationBuilders.nested(aggName(), NESTED_PATH) | ||
61 | - .subAggregation(AggregationBuilders.filter(filterName(), boolFilter) | ||
62 | - .subAggregation(AggregationBuilders.terms(SUB_AGG_NAME).field(ProductIndexEsField.customizeTagsId).size(AGG_COUNT).order(Terms.Order.count(false)))); | ||
63 | - return nestedAggregationBuilder; | ||
64 | - } | ||
65 | - | ||
66 | - @Override | ||
67 | - public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { | ||
68 | - InternalNested aggregation = (InternalNested) aggMaps.get(aggName()); | ||
69 | - if (CollectionUtils.isEmpty(aggregation.getAggregations().asList())) { | ||
70 | - return new ArrayList<>(); | ||
71 | - } | ||
72 | - InternalFilter filter = (InternalFilter) aggregation.getAggregations().asList().get(0); | ||
73 | - List<LongTerms.Bucket> longTerms = ((LongTerms) filter.getAggregations().asList().get(0)).getBucketsInternal(); | ||
74 | - Set<String> tagIdSet = longTerms.stream().map(e -> e.getKeyAsNumber().intValue() + "").collect(Collectors.toSet()); | ||
75 | - if (CollectionUtils.isEmpty(tagIdSet)) { | ||
76 | - return new ArrayList<>(); | ||
77 | - } | ||
78 | - return customizeTagBaseService.getTagListByIds(tagIdSet); | ||
79 | - } | 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.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 | + | ||
11 | +import java.util.ArrayList; | ||
12 | +import java.util.Iterator; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Map; | ||
15 | + | ||
16 | +/** | ||
17 | + * Created by wangnan on 2017/9/12. | ||
18 | + */ | ||
19 | +public class CustomizeTagAggregation extends AbstractAggregation { | ||
20 | + private static int AGG_COUNT = 500; | ||
21 | + private CustomizeTagBaseService customizeTagBaseService; | ||
22 | + | ||
23 | + CustomizeTagAggregation(CustomizeTagBaseService customizeBaseService, Map<String, String> paramMap) { | ||
24 | + this.customizeTagBaseService = customizeBaseService; | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + public String aggName() { | ||
29 | + return "customizeTagAggNew"; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public String filterName() { | ||
34 | + return "customizeTagFilterNew"; | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public AbstractAggregationBuilder<?> getBuilder() { | ||
39 | + return AggregationBuilders.terms(aggName()).field(ProductIndexEsField.poolIds).size(AGG_COUNT); | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { | ||
44 | + try { | ||
45 | + MultiBucketsAggregation aggregation = this.getAggregation(aggMaps); | ||
46 | + if (aggregation == null) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + List<String> poolIdList = new ArrayList<>(); | ||
50 | + Iterator<? extends MultiBucketsAggregation.Bucket> itPoolIdAgg = aggregation.getBuckets().iterator(); | ||
51 | + while (itPoolIdAgg.hasNext()) { | ||
52 | + MultiBucketsAggregation.Bucket itPoolId = itPoolIdAgg.next(); | ||
53 | + for (String poolId : itPoolId.getKeyAsString().split(",")) { | ||
54 | + poolIdList.add(poolId); | ||
55 | + } | ||
56 | + } | ||
57 | + return customizeTagBaseService.getTagListByIds(poolIdList); | ||
58 | + } catch (Exception e) { | ||
59 | + logger.error(e.getMessage(), e); | ||
60 | + } | ||
61 | + return new Object(); | ||
62 | + } | ||
80 | } | 63 | } |
1 | package com.yoho.search.service.helper; | 1 | package com.yoho.search.service.helper; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import com.yoho.search.aop.productlist.ProductListWithSkn; | ||
4 | import com.yoho.search.base.utils.ProductIndexEsField; | 5 | import com.yoho.search.base.utils.ProductIndexEsField; |
5 | import com.yoho.search.core.es.model.SearchParam; | 6 | import com.yoho.search.core.es.model.SearchParam; |
6 | import com.yoho.search.core.es.model.SearchResult; | 7 | import com.yoho.search.core.es.model.SearchResult; |
7 | -import com.yoho.search.aop.productlist.ProductListWithSkn; | ||
8 | -import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum; | 8 | +import com.yoho.search.service.index.CustomizeTagBaseService; |
9 | import com.yoho.search.service.index.ProductIndexBaseService; | 9 | import com.yoho.search.service.index.ProductIndexBaseService; |
10 | import com.yoho.search.service.index.ProductPricePlanIndexBaseService; | 10 | import com.yoho.search.service.index.ProductPricePlanIndexBaseService; |
11 | import com.yoho.search.service.index.promotion.PromotionIndexBaseService; | 11 | import com.yoho.search.service.index.promotion.PromotionIndexBaseService; |
12 | import com.yoho.search.service.index.promotion.PromotionPriceService; | 12 | import com.yoho.search.service.index.promotion.PromotionPriceService; |
13 | +import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum; | ||
13 | import org.apache.commons.collections.MapUtils; | 14 | import org.apache.commons.collections.MapUtils; |
14 | import org.apache.commons.lang.StringUtils; | 15 | import org.apache.commons.lang.StringUtils; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -38,6 +39,8 @@ public class ProductListHelper { | @@ -38,6 +39,8 @@ public class ProductListHelper { | ||
38 | private PromotionIndexBaseService promotionIndexBaseService; | 39 | private PromotionIndexBaseService promotionIndexBaseService; |
39 | @Autowired | 40 | @Autowired |
40 | private PromotionPriceService promotionPriceService; | 41 | private PromotionPriceService promotionPriceService; |
42 | + @Autowired | ||
43 | + private CustomizeTagBaseService customizeTagBaseService; | ||
41 | 44 | ||
42 | public SearchParam buildProductListSearchParam(Map<String, String> paramMap, boolean needPersional) throws Exception { | 45 | public SearchParam buildProductListSearchParam(Map<String, String> paramMap, boolean needPersional) throws Exception { |
43 | return this.innerBuildProductListSearchParam(paramMap, needPersional, false); | 46 | return this.innerBuildProductListSearchParam(paramMap, needPersional, false); |
@@ -117,6 +120,7 @@ public class ProductListHelper { | @@ -117,6 +120,7 @@ public class ProductListHelper { | ||
117 | productPricePlanIndexBaseService.fillProductPricePlan(productReturnInfoList); | 120 | productPricePlanIndexBaseService.fillProductPricePlan(productReturnInfoList); |
118 | promotionIndexBaseService.fillPromotionTag(productReturnInfoList); | 121 | promotionIndexBaseService.fillPromotionTag(productReturnInfoList); |
119 | promotionPriceService.fillPromotionPrice(productReturnInfoList); | 122 | promotionPriceService.fillPromotionPrice(productReturnInfoList); |
123 | + customizeTagBaseService.fillCustomizeTag(productReturnInfoList); | ||
120 | return productReturnInfoList; | 124 | return productReturnInfoList; |
121 | } | 125 | } |
122 | 126 |
@@ -382,7 +382,7 @@ public class SearchCommonHelper { | @@ -382,7 +382,7 @@ public class SearchCommonHelper { | ||
382 | * @param paramMap | 382 | * @param paramMap |
383 | * @return | 383 | * @return |
384 | */ | 384 | */ |
385 | - public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) { | 385 | + public BoolQueryBuilder getActivityTagBuilder(Map<String, String> paramMap) { |
386 | if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) { | 386 | if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) { |
387 | int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ","); | 387 | int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ","); |
388 | BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery(); | 388 | BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery(); |
@@ -391,4 +391,14 @@ public class SearchCommonHelper { | @@ -391,4 +391,14 @@ public class SearchCommonHelper { | ||
391 | } | 391 | } |
392 | return null; | 392 | return null; |
393 | } | 393 | } |
394 | + | ||
395 | + /** | ||
396 | + * 自定义标签过滤 | ||
397 | + */ | ||
398 | + public void getCustomizeTagBuilder(Map<String, String> paramMap, BoolQueryBuilder boolFilter) { | ||
399 | + if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG_NEW) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG_NEW)) { | ||
400 | + int[] poolIds = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG_NEW), ","); | ||
401 | + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.poolIds, poolIds)); | ||
402 | + } | ||
403 | + } | ||
394 | } | 404 | } |
@@ -326,12 +326,15 @@ public class SearchQueryHelper { | @@ -326,12 +326,15 @@ public class SearchQueryHelper { | ||
326 | boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder, ScoreMode.None)); | 326 | boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder, ScoreMode.None)); |
327 | } | 327 | } |
328 | 328 | ||
329 | - // 自定义标签 | ||
330 | - BoolQueryBuilder customizeTagsTermsBuilder = searchCommonHelper.getCustomizeTagBuilder(paramMap); | 329 | + // 自定义标签:旧 |
330 | + BoolQueryBuilder customizeTagsTermsBuilder = searchCommonHelper.getActivityTagBuilder(paramMap); | ||
331 | if (customizeTagsTermsBuilder != null) { | 331 | if (customizeTagsTermsBuilder != null) { |
332 | boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.customizeTags, customizeTagsTermsBuilder, ScoreMode.None)); | 332 | boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.customizeTags, customizeTagsTermsBuilder, ScoreMode.None)); |
333 | } | 333 | } |
334 | 334 | ||
335 | + // 自定义标签:新 | ||
336 | + searchCommonHelper.getCustomizeTagBuilder(paramMap,boolFilter); | ||
337 | + | ||
335 | // 用户VIP级别过滤 | 338 | // 用户VIP级别过滤 |
336 | if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_USER_VIP_LEVEL)) { | 339 | if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_USER_VIP_LEVEL)) { |
337 | List<String> userVipLevels = this.getUserVipLevels(paramMap.get(SearchRequestParams.PARAM_SEARCH_USER_VIP_LEVEL)); | 340 | List<String> userVipLevels = this.getUserVipLevels(paramMap.get(SearchRequestParams.PARAM_SEARCH_USER_VIP_LEVEL)); |
1 | +package com.yoho.search.service.index; | ||
2 | + | ||
3 | +import com.yoho.search.base.utils.ISearchConstants; | ||
4 | +import com.yoho.search.common.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 ActivityTagBaseService { | ||
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.index; | ||
2 | - | ||
3 | -import com.yoho.search.base.utils.ISearchConstants; | ||
4 | -import com.yoho.search.common.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.index; |
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.google.common.cache.CacheBuilder; | ||
5 | +import com.google.common.cache.CacheLoader; | ||
6 | +import com.google.common.cache.LoadingCache; | ||
7 | +import com.yoho.search.base.utils.ConvertUtils; | ||
8 | +import com.yoho.search.base.utils.DateUtil; | ||
9 | +import com.yoho.search.base.utils.ISearchConstants; | ||
10 | +import com.yoho.search.common.SearchCommonService; | ||
11 | +import com.yoho.search.core.es.model.SearchParam; | ||
12 | +import com.yoho.search.core.es.model.SearchResult; | ||
13 | +import com.yoho.search.dal.model.CustomizeTag; | ||
14 | +import org.apache.commons.collections.CollectionUtils; | ||
15 | +import org.apache.commons.collections.MapUtils; | ||
16 | +import org.elasticsearch.index.query.BoolQueryBuilder; | ||
17 | +import org.elasticsearch.index.query.QueryBuilders; | ||
18 | +import org.slf4j.Logger; | ||
19 | +import org.slf4j.LoggerFactory; | ||
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
21 | +import org.springframework.stereotype.Service; | ||
22 | +import org.springframework.util.Assert; | ||
23 | +import org.springframework.util.StringUtils; | ||
24 | + | ||
25 | +import java.util.*; | ||
26 | +import java.util.concurrent.TimeUnit; | ||
27 | +import java.util.stream.Collectors; | ||
28 | + | ||
29 | +/** | ||
30 | + * Created by wangnan on 2017/9/12. | ||
31 | + */ | ||
32 | +@Service | ||
33 | +public class CustomizeTagBaseService { | ||
34 | + | ||
35 | + @Autowired | ||
36 | + private SearchCommonService searchCommonService; | ||
37 | + | ||
38 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
39 | + private static final String CACHE_KEY = "CacheKey"; | ||
40 | + private static final String POOLID_CUSTOMIZETAG_MAP_CACHE_KEY = "poolIdCustomizeTagMapCacheKey"; | ||
41 | + private static final String PRODUCTINDEX_FIELD_POOLIDS = "pool_ids"; | ||
42 | + | ||
43 | + //Guava Cache | ||
44 | + LoadingCache<String, JSONObject> customizeTagCache = CacheBuilder.newBuilder() | ||
45 | + .maximumSize(30000) | ||
46 | + .expireAfterWrite(5, TimeUnit.MINUTES) | ||
47 | + .build(new CacheLoader<String, JSONObject>() { | ||
48 | + public JSONObject load(String key) { | ||
49 | + JSONObject jsonObject = new JSONObject(); | ||
50 | + jsonObject.put(POOLID_CUSTOMIZETAG_MAP_CACHE_KEY, buildCustomizeTagMap()); | ||
51 | + return jsonObject; | ||
52 | + } | ||
53 | + }); | ||
54 | + | ||
55 | + /** | ||
56 | + * 给列表中的每个skn加入自定义标签节点 | ||
57 | + */ | ||
58 | + public void fillCustomizeTag(List<Map<String, Object>> productList) { | ||
59 | + try { | ||
60 | + //1、判断 | ||
61 | + if (CollectionUtils.isEmpty(productList)) { | ||
62 | + return; | ||
63 | + } | ||
64 | + //2、获取poolId和customizeTag的map,缓存5分钟 | ||
65 | + Map<String, List<CustomizeTag>> customizeTagMap = this.getCustomizeTagMapFromCache(); | ||
66 | + if (customizeTagMap.isEmpty()) { | ||
67 | + return; | ||
68 | + } | ||
69 | + //3、遍历product列表,插入customizeTag | ||
70 | + for (Map<String, Object> productMap : productList) { | ||
71 | + String poolIds = MapUtils.getString(productMap, PRODUCTINDEX_FIELD_POOLIDS, ""); | ||
72 | + if (StringUtils.isEmpty(poolIds)) { | ||
73 | + continue; | ||
74 | + } | ||
75 | + List<JSONObject> customizeTags = this.buildCustomizeTag(poolIds, customizeTagMap); | ||
76 | + productMap.put("customize_tag_new", customizeTags); | ||
77 | + } | ||
78 | + } catch (Exception e) { | ||
79 | + logger.error(e.getMessage()); | ||
80 | + } | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * 从缓存中获取poolId->CustomizeTags映射,用于构建列表customizeTag | ||
85 | + */ | ||
86 | + private Map<String, List<CustomizeTag>> getCustomizeTagMapFromCache() throws Exception { | ||
87 | + JSONObject jsonObject = customizeTagCache.get(CACHE_KEY); | ||
88 | + Assert.isTrue(jsonObject != null, "[cache jsonObject cannot be null][fun=getCustomizeTagMapFromCache]"); | ||
89 | + return (Map<String, List<CustomizeTag>>) jsonObject.get(POOLID_CUSTOMIZETAG_MAP_CACHE_KEY); | ||
90 | + } | ||
91 | + | ||
92 | + | ||
93 | + /** | ||
94 | + * 根据poolIds生成自定义标签节点 | ||
95 | + */ | ||
96 | + private List<JSONObject> buildCustomizeTag(String poolIds, Map<String, List<CustomizeTag>> customizeTagBOMap) throws Exception { | ||
97 | + String[] poolIdArray = poolIds.split(","); | ||
98 | + if (poolIdArray.length == 0) { | ||
99 | + return new ArrayList<>(); | ||
100 | + } | ||
101 | + List<String> poolIdList = Arrays.asList(poolIdArray); | ||
102 | + List<JSONObject> customizeTagList = new ArrayList<>(); | ||
103 | + for (String poolId : poolIdList) { | ||
104 | + List<CustomizeTag> customizeTagBOS = customizeTagBOMap.get(poolId); | ||
105 | + if (CollectionUtils.isEmpty(customizeTagBOS)) { | ||
106 | + continue; | ||
107 | + } | ||
108 | + //按照开始时间排序 | ||
109 | + List<CustomizeTag> sortedCustomizeTagList = customizeTagBOS.stream().sorted(Comparator.comparingInt(CustomizeTag::getBeginTime).reversed()).collect(Collectors.toList()); | ||
110 | + if (CollectionUtils.isEmpty(sortedCustomizeTagList)) { | ||
111 | + continue; | ||
112 | + } | ||
113 | + //取第一个 | ||
114 | + CustomizeTag customizeTag = sortedCustomizeTagList.get(0); | ||
115 | + JSONObject tag = new JSONObject(); | ||
116 | + tag.put("id", customizeTag.getId()); | ||
117 | + tag.put("name", customizeTag.getActivityName()); | ||
118 | + tag.put("url", customizeTag.getTagUrl()); | ||
119 | + customizeTagList.add(tag); | ||
120 | + } | ||
121 | + return customizeTagList; | ||
122 | + } | ||
123 | + | ||
124 | + | ||
125 | + /** | ||
126 | + * 构建poolId->ActivityTagBO Map | ||
127 | + */ | ||
128 | + private Map<String, List<CustomizeTag>> buildCustomizeTagMap() { | ||
129 | + try { | ||
130 | + Map<String, List<CustomizeTag>> customizeTagBOMap = new HashMap(); | ||
131 | + List<CustomizeTag> customizeTagList = getCustomizeTags(false, null); | ||
132 | + if (CollectionUtils.isEmpty(customizeTagList)) { | ||
133 | + return new HashMap<>(); | ||
134 | + } | ||
135 | + for (CustomizeTag customizeTag : customizeTagList) { | ||
136 | + String poolIds = customizeTag.getPoolId(); | ||
137 | + String[] poolIdsArray = poolIds.split(","); | ||
138 | + if (poolIdsArray == null) { | ||
139 | + continue; | ||
140 | + } | ||
141 | + for (int i = 0; i < poolIdsArray.length; i++) { | ||
142 | + if (customizeTagBOMap.containsKey(poolIdsArray[i])) { | ||
143 | + List<CustomizeTag> customizeTags = customizeTagBOMap.get(poolIdsArray[i]); | ||
144 | + customizeTags.add(customizeTag); | ||
145 | + } else { | ||
146 | + List<CustomizeTag> customizeTags = new ArrayList<>(); | ||
147 | + customizeTags.add(customizeTag); | ||
148 | + customizeTagBOMap.put(poolIdsArray[i], customizeTags); | ||
149 | + } | ||
150 | + } | ||
151 | + } | ||
152 | + return customizeTagBOMap; | ||
153 | + } catch (Exception e) { | ||
154 | + logger.error(e.getMessage(), e); | ||
155 | + return new HashMap<>(); | ||
156 | + } | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * 查CustomizeTag索引,可以查指定的poolId的 | ||
161 | + */ | ||
162 | + private List<CustomizeTag> getCustomizeTags(boolean filterPoolId, String poolIdsString) throws Exception { | ||
163 | + SearchParam searchParam = new SearchParam(); | ||
164 | + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | ||
165 | + if (filterPoolId) { | ||
166 | + if (StringUtils.isEmpty(poolIdsString)) { | ||
167 | + return new ArrayList<>(); | ||
168 | + } | ||
169 | + int[] poolIds = ConvertUtils.stringToIntArray(poolIdsString, ","); | ||
170 | + boolQueryBuilder.must(QueryBuilders.termsQuery("poolId", poolIds)); | ||
171 | + } | ||
172 | + boolQueryBuilder.must(QueryBuilders.termQuery("status", 1)); | ||
173 | + long currentTime = DateUtil.getCurrentTimeSecond(); | ||
174 | + boolQueryBuilder.must(QueryBuilders.rangeQuery("beginTime").lt(currentTime)); | ||
175 | + boolQueryBuilder.must(QueryBuilders.rangeQuery("endTime").gt(currentTime)); | ||
176 | + searchParam.setFiter(boolQueryBuilder); | ||
177 | + searchParam.setSize(10000); | ||
178 | + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_CUSTOMIZE_TAG, searchParam); | ||
179 | + if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) { | ||
180 | + return Collections.emptyList(); | ||
181 | + } | ||
182 | + List<CustomizeTag> resultList = new ArrayList<>(); | ||
183 | + for (Map<String, Object> esMap : searchResult.getResultList()) { | ||
184 | + if (!esMap.isEmpty()) { | ||
185 | + resultList.add(parseCustomizeTagInfo(esMap)); | ||
186 | + } | ||
187 | + } | ||
188 | + return resultList; | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * CustomizeTag索引数据映射到BO | ||
193 | + */ | ||
194 | + private CustomizeTag parseCustomizeTagInfo(Map<String, Object> esMap) { | ||
195 | + CustomizeTag customizeTagBO = new CustomizeTag(); | ||
196 | + customizeTagBO.setId(MapUtils.getIntValue(esMap, "id", 0)); | ||
197 | + customizeTagBO.setActivityName(MapUtils.getString(esMap, "activityName", "")); | ||
198 | + customizeTagBO.setTagUrl(MapUtils.getString(esMap, "tagUrl", "")); | ||
199 | + customizeTagBO.setPoolId(MapUtils.getString(esMap, "poolId", "")); | ||
200 | + customizeTagBO.setBeforeImgUrl(MapUtils.getString(esMap, "beforeImgUrl", "")); | ||
201 | + customizeTagBO.setAfterImgUrl(MapUtils.getString(esMap, "afterImgUrl", "")); | ||
202 | + customizeTagBO.setBeginTime(MapUtils.getIntValue(esMap, "beginTime", 0)); | ||
203 | + customizeTagBO.setEndTime(MapUtils.getIntValue(esMap, "endTime", 0)); | ||
204 | + return customizeTagBO; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * 用于聚合里返回自定义标签 | ||
209 | + */ | ||
210 | + public List<Map<String, Object>> getTagListByIds(List<String> poolIdList) { | ||
211 | + try { | ||
212 | + String poolIdsString = poolIdList.stream().collect(Collectors.joining(",")); | ||
213 | + List<CustomizeTag> customizeTagBOList = this.getCustomizeTags(true, poolIdsString); | ||
214 | + if (CollectionUtils.isEmpty(customizeTagBOList)) { | ||
215 | + return new ArrayList<>(); | ||
216 | + } | ||
217 | + List<CustomizeTag> sortedCustomizeTags = customizeTagBOList.stream().sorted(Comparator.comparingInt(CustomizeTag::getBeginTime).reversed()).collect(Collectors.toList()); | ||
218 | + if (CollectionUtils.isEmpty(sortedCustomizeTags)) { | ||
219 | + return new ArrayList<>(); | ||
220 | + } | ||
221 | + List<Map<String, Object>> resultList = new ArrayList<>(); | ||
222 | + sortedCustomizeTags.stream().forEach(p -> resultList.add(this.getTagMap(p))); | ||
223 | + return resultList; | ||
224 | + } catch (Exception e) { | ||
225 | + logger.error(e.getMessage(), e); | ||
226 | + } | ||
227 | + return new ArrayList<>(); | ||
228 | + } | ||
229 | + | ||
230 | + private Map<String, Object> getTagMap(CustomizeTag customizeTagBO) { | ||
231 | + Map<String, Object> map = new HashMap<>(); | ||
232 | + map.put("id", customizeTagBO.getPoolId()); | ||
233 | + map.put("name", customizeTagBO.getActivityName()); | ||
234 | + map.put("beforeImgUrl", customizeTagBO.getBeforeImgUrl()); | ||
235 | + map.put("afterImgUrl", customizeTagBO.getAfterImgUrl()); | ||
236 | + return map; | ||
237 | + } | ||
238 | +} |
@@ -105,6 +105,8 @@ public class ProductIndexBaseService { | @@ -105,6 +105,8 @@ public class ProductIndexBaseService { | ||
105 | 105 | ||
106 | productIndexIncludeFields.add(ProductIndexEsField.deposit); | 106 | productIndexIncludeFields.add(ProductIndexEsField.deposit); |
107 | productIndexIncludeFields.add(ProductIndexEsField.depositMultiples); | 107 | productIndexIncludeFields.add(ProductIndexEsField.depositMultiples); |
108 | + | ||
109 | + productIndexIncludeFields.add(ProductIndexEsField.poolIds); | ||
108 | } | 110 | } |
109 | 111 | ||
110 | public List<String> getProductIndexIncludeFields() { | 112 | public List<String> getProductIndexIncludeFields() { |
@@ -212,6 +214,9 @@ public class ProductIndexBaseService { | @@ -212,6 +214,9 @@ public class ProductIndexBaseService { | ||
212 | productMap.put("deposit", MapUtils.getDoubleValue(map, ProductIndexEsField.deposit, 0)); | 214 | productMap.put("deposit", MapUtils.getDoubleValue(map, ProductIndexEsField.deposit, 0)); |
213 | productMap.put("deposit_multiples", MapUtils.getIntValue(map, ProductIndexEsField.depositMultiples)); | 215 | productMap.put("deposit_multiples", MapUtils.getIntValue(map, ProductIndexEsField.depositMultiples)); |
214 | 216 | ||
217 | + //商品池id(活动标签需要用) | ||
218 | + productMap.put("pool_ids", MapUtils.getString(map, ProductIndexEsField.poolIds, "")); | ||
219 | + | ||
215 | return productMap; | 220 | return productMap; |
216 | } | 221 | } |
217 | 222 |
@@ -10,6 +10,7 @@ abstract class AbstractPageSceneService extends BaseSceneService { | @@ -10,6 +10,7 @@ abstract class AbstractPageSceneService extends BaseSceneService { | ||
10 | 10 | ||
11 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; | 11 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; |
12 | protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; | 12 | protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; |
13 | + protected static final String CUSTOMIZE_TAG_LIST_NEW = "customize_tag_new"; | ||
13 | protected static final String STANDARD = "standard"; | 14 | protected static final String STANDARD = "standard"; |
14 | 15 | ||
15 | /** | 16 | /** |
@@ -27,144 +27,145 @@ import java.util.concurrent.Executors; | @@ -27,144 +27,145 @@ import java.util.concurrent.Executors; | ||
27 | @Service | 27 | @Service |
28 | public class FuzzySceneService extends AbstractPageSceneService { | 28 | public class FuzzySceneService extends AbstractPageSceneService { |
29 | 29 | ||
30 | - private static final Logger logger = LoggerFactory.getLogger(FuzzySceneService.class); | ||
31 | - | ||
32 | - @Autowired | ||
33 | - private PageSelectionsService pageSelectionsService; | ||
34 | - @Autowired | ||
35 | - private SearchCommonHelper searchCommonHelper; | ||
36 | - @Autowired | ||
37 | - private RecommendWordsService recommendWordsService; | ||
38 | - @Autowired | ||
39 | - private SearchDynamicConfigService searchDynamicConfigService; | ||
40 | - @Autowired | ||
41 | - private SearchKeyWordHelper searchKeyWordService; | ||
42 | - @Autowired | ||
43 | - private PageAggregationHelper pageAggregationHelper; | ||
44 | - @Autowired | ||
45 | - private PageSelectionsBrandsService scenePageSelectionsBrandsService; | ||
46 | - @Autowired | ||
47 | - private ProductListSwitchService productListSwitchService; | ||
48 | - | ||
49 | - private ExecutorService executor = Executors.newFixedThreadPool(100); | ||
50 | - | ||
51 | - // 当少于20个商品时 返回智能搜索词提示 | ||
52 | - private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | ||
53 | - | ||
54 | - @Override | ||
55 | - public String pageId() { | ||
56 | - return SearchPageIdDefine.PAGE_ID_SEARCH; | ||
57 | - } | ||
58 | - | ||
59 | - @Override | ||
60 | - public void addParamsToParamMap(Map<String, String> paramMap) { | ||
61 | - super.addDefaultParamsToParamMap(paramMap); | ||
62 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购 | ||
63 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词 | ||
64 | - } | ||
65 | - | ||
66 | - /** | ||
67 | - * @1、返回商品列表 | ||
68 | - * @2、数量太多则返回建议词 | ||
69 | - */ | ||
70 | - @Override | ||
71 | - public SearchApiResult productList(Map<String, String> paramMap) { | ||
72 | - try { | ||
73 | - // 1、参数校验 | ||
74 | - if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) { | ||
75 | - return new SearchApiResult().setCode(400).setMessage("请传query参数"); | ||
76 | - } | ||
77 | - // 2、添加默认参数 | ||
78 | - this.addParamsToParamMap(paramMap); | ||
79 | - // 3、获取商品列表 | ||
80 | - CompletableFuture<SearchApiResult> productListuture = CompletableFuture.supplyAsync(() -> productListSwitchService.fuzzyProductList(this.newParamMap(paramMap)), executor); | ||
81 | - // 4、获取自定义标签聚合结果 | ||
82 | - CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), executor); | ||
83 | - // 5、获取促销专题 | ||
84 | - CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggPromotion(this.newParamMap(paramMap)), | ||
85 | - executor); | ||
86 | - | ||
87 | - // 6、加入建议词 | ||
88 | - SearchApiResult productListResult = productListuture.get(); | ||
89 | - this.addSuggestion(productListResult, paramMap); | ||
90 | - | ||
91 | - // 7、模糊搜索页记录关键字对应的查询结果 | ||
92 | - String queryWord = paramMap.get("query"); | ||
93 | - if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) { | ||
94 | - long total = ((JSONObject) productListResult.getData()).getLongValue("total"); | ||
95 | - searchKeyWordService.recordKeyWordByResultCount(queryWord, total); | ||
96 | - } | ||
97 | - // 8、组合结果 | ||
98 | - SearchApiResult customizeTags = customizeTagFuture.get(); | ||
99 | - SearchApiResult promotions = promotionsFuture.get(); | ||
100 | - JSONObject dataMap = (JSONObject) productListResult.getData(); | ||
101 | - dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | ||
102 | - dataMap.put(RECOMMEND_PROMOTION_LIST, pageAggregationHelper.subRecommendPromotions(promotions.getData(),this.getPage(paramMap),1)); | ||
103 | - return productListResult; | ||
104 | - } catch (Exception e) { | ||
105 | - logger.error(e.getMessage(), e); | ||
106 | - return SearchApiResultUtils.errorSearchApiResult("fuzzyProductList", paramMap, e); | ||
107 | - } | ||
108 | - } | ||
109 | - | ||
110 | - @Override | ||
111 | - public SearchApiResult aggregations(Map<String, String> paramMap) { | ||
112 | - try { | ||
113 | - // 0、参数校验 | ||
114 | - if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) { | ||
115 | - return new SearchApiResult().setCode(400).setMessage("请传query参数"); | ||
116 | - } | ||
117 | - // 1、添加默认参数 | ||
118 | - this.addParamsToParamMap(paramMap); | ||
119 | - // 2、返回聚合结果 | ||
120 | - SearchApiResult result = pageSelectionsService.aggregations(paramMap); | ||
121 | - scenePageSelectionsBrandsService.getRecommendBrands(paramMap, result); | ||
122 | - return result; | ||
123 | - } catch (Exception e) { | ||
124 | - logger.error(e.getMessage(), e); | ||
125 | - return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500); | ||
126 | - } | ||
127 | - } | ||
128 | - | ||
129 | - /** | ||
130 | - * 获取模糊搜索的推荐词 | ||
131 | - * | ||
132 | - * @param paramMap | ||
133 | - * @return | ||
134 | - */ | ||
135 | - public void addSuggestion(SearchApiResult searchResult, Map<String, String> paramMap) { | ||
136 | - if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) { | ||
137 | - return; | ||
138 | - } | ||
139 | - // 1. 判断是否需要进行term推荐 | ||
140 | - // 1.1 query不为空 | ||
141 | - String queryWord = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY); | ||
142 | - if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySknOrSku(queryWord))) { | ||
143 | - return; | ||
144 | - } | ||
145 | - // 1.2不是第一页直接不返回 | ||
146 | - int page = this.getPage(paramMap); | ||
147 | - if (page != 1) { | ||
148 | - return; | ||
149 | - } | ||
150 | - // 1.3请求制定需要返回term推荐 | ||
151 | - if (!"Y".equalsIgnoreCase(paramMap.get(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION))) { | ||
152 | - return; | ||
153 | - } | ||
154 | - | ||
155 | - // 1.4打开智能推荐全局开关 | ||
156 | - if (!searchDynamicConfigService.isSearchSuggestionTipsOpen()) { | ||
157 | - return; | ||
158 | - } | ||
159 | - | ||
160 | - // 1.5 搜索的数量小于20条 | ||
161 | - JSONObject dataMap = ((JSONObject) searchResult.getData()); | ||
162 | - if (dataMap.getIntValue("total") >= SMART_SUGGESTION_PRODUCT_LIMIT) { | ||
163 | - return; | ||
164 | - } | ||
165 | - | ||
166 | - // 1.6加入推荐词 | ||
167 | - dataMap.put("suggestion", recommendWordsService.recommendWords(searchResult, paramMap)); | ||
168 | - } | 30 | + private static final Logger logger = LoggerFactory.getLogger(FuzzySceneService.class); |
31 | + | ||
32 | + @Autowired | ||
33 | + private PageSelectionsService pageSelectionsService; | ||
34 | + @Autowired | ||
35 | + private SearchCommonHelper searchCommonHelper; | ||
36 | + @Autowired | ||
37 | + private RecommendWordsService recommendWordsService; | ||
38 | + @Autowired | ||
39 | + private SearchDynamicConfigService searchDynamicConfigService; | ||
40 | + @Autowired | ||
41 | + private SearchKeyWordHelper searchKeyWordService; | ||
42 | + @Autowired | ||
43 | + private PageAggregationHelper pageAggregationHelper; | ||
44 | + @Autowired | ||
45 | + private PageSelectionsBrandsService scenePageSelectionsBrandsService; | ||
46 | + @Autowired | ||
47 | + private ProductListSwitchService productListSwitchService; | ||
48 | + | ||
49 | + private ExecutorService executor = Executors.newFixedThreadPool(100); | ||
50 | + | ||
51 | + // 当少于20个商品时 返回智能搜索词提示 | ||
52 | + private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | ||
53 | + | ||
54 | + @Override | ||
55 | + public String pageId() { | ||
56 | + return SearchPageIdDefine.PAGE_ID_SEARCH; | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public void addParamsToParamMap(Map<String, String> paramMap) { | ||
61 | + super.addDefaultParamsToParamMap(paramMap); | ||
62 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购 | ||
63 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词 | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * @1、返回商品列表 | ||
68 | + * @2、数量太多则返回建议词 | ||
69 | + */ | ||
70 | + @Override | ||
71 | + public SearchApiResult productList(Map<String, String> paramMap) { | ||
72 | + try { | ||
73 | + // 1、参数校验 | ||
74 | + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) { | ||
75 | + return new SearchApiResult().setCode(400).setMessage("请传query参数"); | ||
76 | + } | ||
77 | + // 2、添加默认参数 | ||
78 | + this.addParamsToParamMap(paramMap); | ||
79 | + // 3、获取商品列表 | ||
80 | + CompletableFuture<SearchApiResult> productListuture = CompletableFuture.supplyAsync(() -> productListSwitchService.fuzzyProductList(this.newParamMap(paramMap)), executor); | ||
81 | + // 4、获取自定义标签聚合结果-旧 | ||
82 | + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), executor); | ||
83 | + // 4、获取自定义标签聚合结果-新 | ||
84 | + CompletableFuture<SearchApiResult> customizeTagFutureNew = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTagNew(this.newParamMap(paramMap)), executor); | ||
85 | + // 5、获取促销专题 | ||
86 | + CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggPromotion(this.newParamMap(paramMap)), | ||
87 | + executor); | ||
88 | + | ||
89 | + // 6、加入建议词 | ||
90 | + SearchApiResult productListResult = productListuture.get(); | ||
91 | + this.addSuggestion(productListResult, paramMap); | ||
92 | + | ||
93 | + // 7、模糊搜索页记录关键字对应的查询结果 | ||
94 | + String queryWord = paramMap.get("query"); | ||
95 | + if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) { | ||
96 | + long total = ((JSONObject) productListResult.getData()).getLongValue("total"); | ||
97 | + searchKeyWordService.recordKeyWordByResultCount(queryWord, total); | ||
98 | + } | ||
99 | + // 8、组合结果 | ||
100 | + SearchApiResult customizeTags = customizeTagFuture.get(); | ||
101 | + SearchApiResult customizeTagsNew = customizeTagFutureNew.get(); | ||
102 | + SearchApiResult promotions = promotionsFuture.get(); | ||
103 | + JSONObject dataMap = (JSONObject) productListResult.getData(); | ||
104 | + dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | ||
105 | + dataMap.put(CUSTOMIZE_TAG_LIST_NEW, customizeTagsNew.getData()); | ||
106 | + dataMap.put(RECOMMEND_PROMOTION_LIST, pageAggregationHelper.subRecommendPromotions(promotions.getData(), this.getPage(paramMap), 1)); | ||
107 | + return productListResult; | ||
108 | + } catch (Exception e) { | ||
109 | + logger.error(e.getMessage(), e); | ||
110 | + return SearchApiResultUtils.errorSearchApiResult("fuzzyProductList", paramMap, e); | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public SearchApiResult aggregations(Map<String, String> paramMap) { | ||
116 | + try { | ||
117 | + // 0、参数校验 | ||
118 | + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) { | ||
119 | + return new SearchApiResult().setCode(400).setMessage("请传query参数"); | ||
120 | + } | ||
121 | + // 1、添加默认参数 | ||
122 | + this.addParamsToParamMap(paramMap); | ||
123 | + // 2、返回聚合结果 | ||
124 | + SearchApiResult result = pageSelectionsService.aggregations(paramMap); | ||
125 | + scenePageSelectionsBrandsService.getRecommendBrands(paramMap, result); | ||
126 | + return result; | ||
127 | + } catch (Exception e) { | ||
128 | + logger.error(e.getMessage(), e); | ||
129 | + return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500); | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * 获取模糊搜索的推荐词 | ||
135 | + */ | ||
136 | + public void addSuggestion(SearchApiResult searchResult, Map<String, String> paramMap) { | ||
137 | + if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) { | ||
138 | + return; | ||
139 | + } | ||
140 | + // 1. 判断是否需要进行term推荐 | ||
141 | + // 1.1 query不为空 | ||
142 | + String queryWord = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY); | ||
143 | + if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySknOrSku(queryWord))) { | ||
144 | + return; | ||
145 | + } | ||
146 | + // 1.2不是第一页直接不返回 | ||
147 | + int page = this.getPage(paramMap); | ||
148 | + if (page != 1) { | ||
149 | + return; | ||
150 | + } | ||
151 | + // 1.3请求制定需要返回term推荐 | ||
152 | + if (!"Y".equalsIgnoreCase(paramMap.get(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION))) { | ||
153 | + return; | ||
154 | + } | ||
155 | + | ||
156 | + // 1.4打开智能推荐全局开关 | ||
157 | + if (!searchDynamicConfigService.isSearchSuggestionTipsOpen()) { | ||
158 | + return; | ||
159 | + } | ||
160 | + | ||
161 | + // 1.5 搜索的数量小于20条 | ||
162 | + JSONObject dataMap = ((JSONObject) searchResult.getData()); | ||
163 | + if (dataMap.getIntValue("total") >= SMART_SUGGESTION_PRODUCT_LIMIT) { | ||
164 | + return; | ||
165 | + } | ||
166 | + | ||
167 | + // 1.6加入推荐词 | ||
168 | + dataMap.put("suggestion", recommendWordsService.recommendWords(searchResult, paramMap)); | ||
169 | + } | ||
169 | 170 | ||
170 | } | 171 | } |
@@ -82,16 +82,20 @@ public class SortPageSceneService extends AbstractPageSceneService { | @@ -82,16 +82,20 @@ public class SortPageSceneService extends AbstractPageSceneService { | ||
82 | executorService); | 82 | executorService); |
83 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), | 83 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), |
84 | executorService); | 84 | executorService); |
85 | + CompletableFuture<SearchApiResult> customizeTagFutureNew = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTagNew(this.newParamMap(paramMap)), | ||
86 | + executorService); | ||
85 | CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggPromotion(this.newParamMap(paramMap)), | 87 | CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggPromotion(this.newParamMap(paramMap)), |
86 | executorService); | 88 | executorService); |
87 | // 3、组合结果 | 89 | // 3、组合结果 |
88 | SearchApiResult productList = productListFuture.get(); | 90 | SearchApiResult productList = productListFuture.get(); |
89 | SearchApiResult standards = standardsFuture.get(); | 91 | SearchApiResult standards = standardsFuture.get(); |
90 | SearchApiResult customizeTags = customizeTagFuture.get(); | 92 | SearchApiResult customizeTags = customizeTagFuture.get(); |
93 | + SearchApiResult customizeTagsNew = customizeTagFutureNew.get(); | ||
91 | SearchApiResult promotions = promotionsFuture.get(); | 94 | SearchApiResult promotions = promotionsFuture.get(); |
92 | JSONObject jsonObject = (JSONObject) productList.getData(); | 95 | JSONObject jsonObject = (JSONObject) productList.getData(); |
93 | jsonObject.put(STANDARD, standards.getData()); | 96 | jsonObject.put(STANDARD, standards.getData()); |
94 | jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | 97 | jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); |
98 | + jsonObject.put(CUSTOMIZE_TAG_LIST_NEW, customizeTagsNew.getData()); | ||
95 | jsonObject.put(RECOMMEND_PROMOTION_LIST, pageAggregationHelper.subRecommendPromotions(promotions.getData(), this.getPage(paramMap), 1)); | 99 | jsonObject.put(RECOMMEND_PROMOTION_LIST, pageAggregationHelper.subRecommendPromotions(promotions.getData(), this.getPage(paramMap), 1)); |
96 | return productList; | 100 | return productList; |
97 | } catch (Exception e) { | 101 | } catch (Exception e) { |
@@ -48,7 +48,7 @@ public class PageAggregationHelper { | @@ -48,7 +48,7 @@ public class PageAggregationHelper { | ||
48 | 48 | ||
49 | /** | 49 | /** |
50 | * 聚合规则-非个性化 | 50 | * 聚合规则-非个性化 |
51 | - * | 51 | + * |
52 | * @param paramMap | 52 | * @param paramMap |
53 | * @return | 53 | * @return |
54 | */ | 54 | */ |
@@ -65,15 +65,15 @@ public class PageAggregationHelper { | @@ -65,15 +65,15 @@ public class PageAggregationHelper { | ||
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | - * 聚合自定义标签-非个性化 | ||
69 | - * | 68 | + * 聚合自定义标签-非个性化-老的 |
69 | + * | ||
70 | * @param paramMap | 70 | * @param paramMap |
71 | * @return | 71 | * @return |
72 | */ | 72 | */ |
73 | @SearchCacheAble(cacheName = "SCENE_AGG_CUSTOMIZETAG", cacheInMinute = 15, excludeParams = { "uid","udid","order", "page", "viewNum", "yh_channel" }) | 73 | @SearchCacheAble(cacheName = "SCENE_AGG_CUSTOMIZETAG", cacheInMinute = 15, excludeParams = { "uid","udid","order", "page", "viewNum", "yh_channel" }) |
74 | public SearchApiResult sceneAggCustomizeTag(Map<String, String> paramMap) { | 74 | public SearchApiResult sceneAggCustomizeTag(Map<String, String> paramMap) { |
75 | try { | 75 | try { |
76 | - IAggregation customizeAggregation = aggregationFactory.getCustomizeTagAggregation(paramMap); | 76 | + IAggregation customizeAggregation = aggregationFactory.getActivityTagAggregation(paramMap); |
77 | Object respone = this.getAggregationResponse(customizeAggregation, paramMap); | 77 | Object respone = this.getAggregationResponse(customizeAggregation, paramMap); |
78 | return new SearchApiResult().setData(respone); | 78 | return new SearchApiResult().setData(respone); |
79 | } catch (Exception e) { | 79 | } catch (Exception e) { |
@@ -82,9 +82,27 @@ public class PageAggregationHelper { | @@ -82,9 +82,27 @@ public class PageAggregationHelper { | ||
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | + /** | ||
86 | + * 聚合自定义标签-非个性化-新的 | ||
87 | + * | ||
88 | + * @param paramMap | ||
89 | + * @return | ||
90 | + */ | ||
91 | + @SearchCacheAble(cacheName = "SCENE_AGG_CUSTOMIZETAG_NEW", cacheInMinute = 15, excludeParams = { "uid","udid","order", "page", "viewNum", "yh_channel" }) | ||
92 | + public SearchApiResult sceneAggCustomizeTagNew(Map<String, String> paramMap) { | ||
93 | + try { | ||
94 | + IAggregation customizeAggregation = aggregationFactory.getCustomizeTagAggregation(paramMap); | ||
95 | + Object respone = this.getAggregationResponse(customizeAggregation, paramMap); | ||
96 | + return new SearchApiResult().setData(respone); | ||
97 | + } catch (Exception e) { | ||
98 | + logger.error(e.getMessage(), e); | ||
99 | + return new SearchApiResult().setCode(500).setMessage("secneAggCustomizeTag Exception"); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
85 | /** | 103 | /** |
86 | * 聚合促销专题-非个性化 | 104 | * 聚合促销专题-非个性化 |
87 | - * | 105 | + * |
88 | * @param paramMap | 106 | * @param paramMap |
89 | * @return | 107 | * @return |
90 | */ | 108 | */ |
@@ -129,7 +147,7 @@ public class PageAggregationHelper { | @@ -129,7 +147,7 @@ public class PageAggregationHelper { | ||
129 | 147 | ||
130 | /** | 148 | /** |
131 | * 从缓存中获取数据后按分页参数截取 | 149 | * 从缓存中获取数据后按分页参数截取 |
132 | - * | 150 | + * |
133 | * @param recommendPromotions | 151 | * @param recommendPromotions |
134 | * @param page | 152 | * @param page |
135 | * @param count | 153 | * @param count |
-
Please register or login to post a comment