Authored by zhaojun2

fix service.service

@@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.ApplicationEventPublisher; 35 import org.springframework.context.ApplicationEventPublisher;
36 import org.springframework.context.ApplicationEventPublisherAware; 36 import org.springframework.context.ApplicationEventPublisherAware;
37 import org.springframework.stereotype.Service; 37 import org.springframework.stereotype.Service;
  38 +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
38 39
39 @Service 40 @Service
40 public class BrandWithShopsService implements ApplicationEventPublisherAware { 41 public class BrandWithShopsService implements ApplicationEventPublisherAware {
@@ -97,7 +98,7 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware { @@ -97,7 +98,7 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware {
97 } 98 }
98 } 99 }
99 100
100 - private MultiBucketsAggregation getMultiBucketsAggregation(MultiBucketsAggregation.Bucket bucket, String aggName) { 101 + private MultiBucketsAggregation getMultiBucketsAggregation(Bucket bucket, String aggName) {
101 return (MultiBucketsAggregation) bucket.getAggregations().asMap().get(aggName); 102 return (MultiBucketsAggregation) bucket.getAggregations().asMap().get(aggName);
102 } 103 }
103 104
@@ -107,18 +108,18 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware { @@ -107,18 +108,18 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware {
107 private Map<String, JSONArray> makeBrandResponse(MultiBucketsAggregation aggregation){ 108 private Map<String, JSONArray> makeBrandResponse(MultiBucketsAggregation aggregation){
108 // 1)获取每个brandAlif-->brandId->List<BrandShopInfo> 109 // 1)获取每个brandAlif-->brandId->List<BrandShopInfo>
109 Map<String, Map<String, List<BrandShopInfo>>> brandAlif2BrandShopInfos = new LinkedHashMap<String, Map<String, List<BrandShopInfo>>>(); 110 Map<String, Map<String, List<BrandShopInfo>>> brandAlif2BrandShopInfos = new LinkedHashMap<String, Map<String, List<BrandShopInfo>>>();
110 - for (MultiBucketsAggregation.Bucket brandAlifBucket : aggregation.getBuckets()) { 111 + for (Bucket brandAlifBucket : aggregation.getBuckets()) {
111 String brandAlif = brandAlifBucket.getKeyAsString(); 112 String brandAlif = brandAlifBucket.getKeyAsString();
112 Map<String, List<BrandShopInfo>> brandWithShopsListMap = new LinkedHashMap<String, List<BrandShopInfo>>(); 113 Map<String, List<BrandShopInfo>> brandWithShopsListMap = new LinkedHashMap<String, List<BrandShopInfo>>();
113 MultiBucketsAggregation brandIdAgg = this.getMultiBucketsAggregation(brandAlifBucket, "brandIdAgg"); 114 MultiBucketsAggregation brandIdAgg = this.getMultiBucketsAggregation(brandAlifBucket, "brandIdAgg");
114 - for (MultiBucketsAggregation.Bucket brandIdBucket : brandIdAgg.getBuckets()) { 115 + for (Bucket brandIdBucket : brandIdAgg.getBuckets()) {
115 String brandId = brandIdBucket.getKeyAsString(); 116 String brandId = brandIdBucket.getKeyAsString();
116 List<BrandShopInfo> brandShopInfoList = new ArrayList<BrandShopInfo>(); 117 List<BrandShopInfo> brandShopInfoList = new ArrayList<BrandShopInfo>();
117 MultiBucketsAggregation shopIdAggs = this.getMultiBucketsAggregation(brandIdBucket, "shopIdAgg"); 118 MultiBucketsAggregation shopIdAggs = this.getMultiBucketsAggregation(brandIdBucket, "shopIdAgg");
118 - for (MultiBucketsAggregation.Bucket shopIdBucket : shopIdAggs.getBuckets()) { 119 + for (Bucket shopIdBucket : shopIdAggs.getBuckets()) {
119 String shopId = shopIdBucket.getKeyAsString(); 120 String shopId = shopIdBucket.getKeyAsString();
120 MultiBucketsAggregation isGlobalAgg = this.getMultiBucketsAggregation(shopIdBucket, "isGlobalAgg"); 121 MultiBucketsAggregation isGlobalAgg = this.getMultiBucketsAggregation(shopIdBucket, "isGlobalAgg");
121 - for (MultiBucketsAggregation.Bucket isGlobalBucket : isGlobalAgg.getBuckets()) { 122 + for (Bucket isGlobalBucket : isGlobalAgg.getBuckets()) {
122 String isGlobal = isGlobalBucket.getKeyAsString(); 123 String isGlobal = isGlobalBucket.getKeyAsString();
123 BrandShopInfo brandShopInfo = new BrandShopInfo(shopId, isGlobal); 124 BrandShopInfo brandShopInfo = new BrandShopInfo(shopId, isGlobal);
124 if (this.isBrandShopInfoLegal(brandShopInfo)) { 125 if (this.isBrandShopInfoLegal(brandShopInfo)) {
@@ -22,6 +22,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder; @@ -22,6 +22,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
22 import com.yoho.search.models.SearchApiResult; 22 import com.yoho.search.models.SearchApiResult;
23 import org.elasticsearch.index.query.QueryBuilder; 23 import org.elasticsearch.index.query.QueryBuilder;
24 import org.elasticsearch.index.query.QueryBuilders; 24 import org.elasticsearch.index.query.QueryBuilders;
  25 +import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory; 26 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired; 27 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service; 28 import org.springframework.stereotype.Service;
@@ -29,7 +30,7 @@ import org.springframework.stereotype.Service; @@ -29,7 +30,7 @@ import org.springframework.stereotype.Service;
29 @Service 30 @Service
30 public class ProductCountService extends AbstractCacheAbleService { 31 public class ProductCountService extends AbstractCacheAbleService {
31 32
32 - private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(ProductCountService.class); 33 + private static final Logger Logger = LoggerFactory.getLogger(ProductCountService.class);
33 34
34 @Autowired 35 @Autowired
35 private SearchCommonService searchCommonService; 36 private SearchCommonService searchCommonService;
1 package com.yoho.search.service.service; 1 package com.yoho.search.service.service;
2 2
3 import java.util.*; 3 import java.util.*;
  4 +import java.util.Map.Entry;
4 5
5 import com.alibaba.fastjson.JSONArray; 6 import com.alibaba.fastjson.JSONArray;
6 import com.alibaba.fastjson.JSONObject; 7 import com.alibaba.fastjson.JSONObject;
@@ -24,6 +25,7 @@ import org.elasticsearch.search.aggregations.Aggregation; @@ -24,6 +25,7 @@ import org.elasticsearch.search.aggregations.Aggregation;
24 25
25 import com.yoho.search.models.SearchApiResult; 26 import com.yoho.search.models.SearchApiResult;
26 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; 27 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
  28 +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
27 import org.springframework.beans.factory.annotation.Autowired; 29 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service; 30 import org.springframework.stereotype.Service;
29 31
@@ -208,9 +210,9 @@ public class SelectionsForApp extends AbstractCacheAbleService { @@ -208,9 +210,9 @@ public class SelectionsForApp extends AbstractCacheAbleService {
208 Object standardResponse = standardAggregation.getAggregationResponseMap(aggMaps); 210 Object standardResponse = standardAggregation.getAggregationResponseMap(aggMaps);
209 if (standardResponse != null) { 211 if (standardResponse != null) {
210 @SuppressWarnings("unchecked") 212 @SuppressWarnings("unchecked")
211 - Iterator<Map.Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator(); 213 + Iterator<Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
212 while (entryStandard.hasNext()) { 214 while (entryStandard.hasNext()) {
213 - Map.Entry<String, Object> entry = entryStandard.next(); 215 + Entry<String, Object> entry = entryStandard.next();
214 if (paramMap.containsKey(entry.getKey())) { 216 if (paramMap.containsKey(entry.getKey())) {
215 filter.put(entry.getKey(), entry.getValue()); 217 filter.put(entry.getKey(), entry.getValue());
216 } else { 218 } else {
@@ -249,9 +251,9 @@ public class SelectionsForApp extends AbstractCacheAbleService { @@ -249,9 +251,9 @@ public class SelectionsForApp extends AbstractCacheAbleService {
249 } 251 }
250 252
251 private boolean getNLSMap(MultiBucketsAggregation aggregation) { 253 private boolean getNLSMap(MultiBucketsAggregation aggregation) {
252 - Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator(); 254 + Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
253 while (itAgg.hasNext()) { 255 while (itAgg.hasNext()) {
254 - MultiBucketsAggregation.Bucket bucket = itAgg.next(); 256 + Bucket bucket = itAgg.next();
255 String bool = bucket.getKeyAsString(); 257 String bool = bucket.getKeyAsString();
256 if ("Y".equals(bool)) { 258 if ("Y".equals(bool)) {
257 return true; 259 return true;
1 package com.yoho.search.service.service; 1 package com.yoho.search.service.service;
2 2
3 import java.util.*; 3 import java.util.*;
  4 +import java.util.Map.Entry;
4 5
5 import com.alibaba.fastjson.JSONArray; 6 import com.alibaba.fastjson.JSONArray;
6 import com.alibaba.fastjson.JSONObject; 7 import com.alibaba.fastjson.JSONObject;
@@ -28,6 +29,7 @@ import com.yoho.search.models.SearchApiResult; @@ -28,6 +29,7 @@ import com.yoho.search.models.SearchApiResult;
28 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; 29 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
29 import org.elasticsearch.search.aggregations.Aggregation; 30 import org.elasticsearch.search.aggregations.Aggregation;
30 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; 31 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
  32 +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
31 import org.slf4j.Logger; 33 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory; 34 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired; 35 import org.springframework.beans.factory.annotation.Autowired;
@@ -342,9 +344,9 @@ public class SelectionsForPc extends AbstractCacheAbleService { @@ -342,9 +344,9 @@ public class SelectionsForPc extends AbstractCacheAbleService {
342 IAggregation standardAggregation = aggregationFactoryService.getStandardAggregation(paramMap); 344 IAggregation standardAggregation = aggregationFactoryService.getStandardAggregation(paramMap);
343 Object standardResponse = this.getResponseByIAggregation(standardAggregation, preAggregationResult, aggMaps); 345 Object standardResponse = this.getResponseByIAggregation(standardAggregation, preAggregationResult, aggMaps);
344 if (standardResponse != null) { 346 if (standardResponse != null) {
345 - Iterator<Map.Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator(); 347 + Iterator<Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
346 while (entryStandard.hasNext()) { 348 while (entryStandard.hasNext()) {
347 - Map.Entry<String, Object> entry = entryStandard.next(); 349 + Entry<String, Object> entry = entryStandard.next();
348 if (paramMap.containsKey(entry.getKey())) { 350 if (paramMap.containsKey(entry.getKey())) {
349 filter.put(entry.getKey(), entry.getValue()); 351 filter.put(entry.getKey(), entry.getValue());
350 } else { 352 } else {
@@ -397,9 +399,9 @@ public class SelectionsForPc extends AbstractCacheAbleService { @@ -397,9 +399,9 @@ public class SelectionsForPc extends AbstractCacheAbleService {
397 } 399 }
398 400
399 private boolean getNLSMap(MultiBucketsAggregation aggregation) { 401 private boolean getNLSMap(MultiBucketsAggregation aggregation) {
400 - Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator(); 402 + Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
401 while (itAgg.hasNext()) { 403 while (itAgg.hasNext()) {
402 - MultiBucketsAggregation.Bucket bucket = itAgg.next(); 404 + Bucket bucket = itAgg.next();
403 // String bool = bucket.getKexy(); 405 // String bool = bucket.getKexy();
404 String bool = bucket.getKeyAsString(); 406 String bool = bucket.getKeyAsString();
405 if ("Y".equals(bool)) { 407 if ("Y".equals(bool)) {
@@ -27,11 +27,13 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; @@ -27,11 +27,13 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder;
27 import org.elasticsearch.index.query.Operator; 27 import org.elasticsearch.index.query.Operator;
28 import org.elasticsearch.index.query.QueryBuilders; 28 import org.elasticsearch.index.query.QueryBuilders;
29 import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; 29 import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
  30 +import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
30 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; 31 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
31 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; 32 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
32 import org.elasticsearch.search.aggregations.Aggregation; 33 import org.elasticsearch.search.aggregations.Aggregation;
33 import org.elasticsearch.search.aggregations.AggregationBuilders; 34 import org.elasticsearch.search.aggregations.AggregationBuilders;
34 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; 35 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
  36 +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
35 import org.elasticsearch.search.aggregations.bucket.terms.Terms; 37 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
36 import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; 38 import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
37 import org.elasticsearch.search.aggregations.metrics.tophits.TopHits; 39 import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
@@ -71,9 +73,9 @@ public class ShopListService { @@ -71,9 +73,9 @@ public class ShopListService {
71 } 73 }
72 queryBuilder.minimumShouldMatch("100%"); 74 queryBuilder.minimumShouldMatch("100%");
73 // 2.1 全球购得分减半 75 // 2.1 全球购得分减半
74 - FunctionScoreQueryBuilder.FilterFunctionBuilder[] filterFunctionBuilders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[2];  
75 - filterFunctionBuilders[0] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));  
76 - filterFunctionBuilders[1] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f)); 76 + FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[2];
  77 + filterFunctionBuilders[0] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));
  78 + filterFunctionBuilders[1] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f));
77 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders); 79 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders);
78 functionScoreQueryBuilder.boostMode(CombineFunction.MULTIPLY); 80 functionScoreQueryBuilder.boostMode(CombineFunction.MULTIPLY);
79 searchParam.setQuery(functionScoreQueryBuilder); 81 searchParam.setQuery(functionScoreQueryBuilder);
@@ -144,10 +146,10 @@ public class ShopListService { @@ -144,10 +146,10 @@ public class ShopListService {
144 * @return 146 * @return
145 */ 147 */
146 private List<Map<String, Object>> getShopList(final MultiBucketsAggregation aggregation) { 148 private List<Map<String, Object>> getShopList(final MultiBucketsAggregation aggregation) {
147 - Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator(); 149 + Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
148 List<Map<String, Object>> productSourceList = new ArrayList<Map<String, Object>>(); 150 List<Map<String, Object>> productSourceList = new ArrayList<Map<String, Object>>();
149 while (itAgg.hasNext()) { 151 while (itAgg.hasNext()) {
150 - MultiBucketsAggregation.Bucket lt = itAgg.next(); 152 + Bucket lt = itAgg.next();
151 if (lt.getAggregations().getAsMap().containsKey("product")) { 153 if (lt.getAggregations().getAsMap().containsKey("product")) {
152 TopHits topHits = lt.getAggregations().get("product"); 154 TopHits topHits = lt.getAggregations().get("product");
153 productSourceList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits)); 155 productSourceList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits));