Authored by zhaojun2

fix service.service

... ... @@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
@Service
public class BrandWithShopsService implements ApplicationEventPublisherAware {
... ... @@ -97,7 +98,7 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware {
}
}
private MultiBucketsAggregation getMultiBucketsAggregation(MultiBucketsAggregation.Bucket bucket, String aggName) {
private MultiBucketsAggregation getMultiBucketsAggregation(Bucket bucket, String aggName) {
return (MultiBucketsAggregation) bucket.getAggregations().asMap().get(aggName);
}
... ... @@ -107,18 +108,18 @@ public class BrandWithShopsService implements ApplicationEventPublisherAware {
private Map<String, JSONArray> makeBrandResponse(MultiBucketsAggregation aggregation){
// 1)获取每个brandAlif-->brandId->List<BrandShopInfo>
Map<String, Map<String, List<BrandShopInfo>>> brandAlif2BrandShopInfos = new LinkedHashMap<String, Map<String, List<BrandShopInfo>>>();
for (MultiBucketsAggregation.Bucket brandAlifBucket : aggregation.getBuckets()) {
for (Bucket brandAlifBucket : aggregation.getBuckets()) {
String brandAlif = brandAlifBucket.getKeyAsString();
Map<String, List<BrandShopInfo>> brandWithShopsListMap = new LinkedHashMap<String, List<BrandShopInfo>>();
MultiBucketsAggregation brandIdAgg = this.getMultiBucketsAggregation(brandAlifBucket, "brandIdAgg");
for (MultiBucketsAggregation.Bucket brandIdBucket : brandIdAgg.getBuckets()) {
for (Bucket brandIdBucket : brandIdAgg.getBuckets()) {
String brandId = brandIdBucket.getKeyAsString();
List<BrandShopInfo> brandShopInfoList = new ArrayList<BrandShopInfo>();
MultiBucketsAggregation shopIdAggs = this.getMultiBucketsAggregation(brandIdBucket, "shopIdAgg");
for (MultiBucketsAggregation.Bucket shopIdBucket : shopIdAggs.getBuckets()) {
for (Bucket shopIdBucket : shopIdAggs.getBuckets()) {
String shopId = shopIdBucket.getKeyAsString();
MultiBucketsAggregation isGlobalAgg = this.getMultiBucketsAggregation(shopIdBucket, "isGlobalAgg");
for (MultiBucketsAggregation.Bucket isGlobalBucket : isGlobalAgg.getBuckets()) {
for (Bucket isGlobalBucket : isGlobalAgg.getBuckets()) {
String isGlobal = isGlobalBucket.getKeyAsString();
BrandShopInfo brandShopInfo = new BrandShopInfo(shopId, isGlobal);
if (this.isBrandShopInfoLegal(brandShopInfo)) {
... ...
... ... @@ -22,6 +22,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import com.yoho.search.models.SearchApiResult;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -29,7 +30,7 @@ import org.springframework.stereotype.Service;
@Service
public class ProductCountService extends AbstractCacheAbleService {
private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(ProductCountService.class);
private static final Logger Logger = LoggerFactory.getLogger(ProductCountService.class);
@Autowired
private SearchCommonService searchCommonService;
... ...
package com.yoho.search.service.service;
import java.util.*;
import java.util.Map.Entry;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
... ... @@ -24,6 +25,7 @@ import org.elasticsearch.search.aggregations.Aggregation;
import com.yoho.search.models.SearchApiResult;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -208,9 +210,9 @@ public class SelectionsForApp extends AbstractCacheAbleService {
Object standardResponse = standardAggregation.getAggregationResponseMap(aggMaps);
if (standardResponse != null) {
@SuppressWarnings("unchecked")
Iterator<Map.Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
Iterator<Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
while (entryStandard.hasNext()) {
Map.Entry<String, Object> entry = entryStandard.next();
Entry<String, Object> entry = entryStandard.next();
if (paramMap.containsKey(entry.getKey())) {
filter.put(entry.getKey(), entry.getValue());
} else {
... ... @@ -249,9 +251,9 @@ public class SelectionsForApp extends AbstractCacheAbleService {
}
private boolean getNLSMap(MultiBucketsAggregation aggregation) {
Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator();
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
while (itAgg.hasNext()) {
MultiBucketsAggregation.Bucket bucket = itAgg.next();
Bucket bucket = itAgg.next();
String bool = bucket.getKeyAsString();
if ("Y".equals(bool)) {
return true;
... ...
package com.yoho.search.service.service;
import java.util.*;
import java.util.Map.Entry;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
... ... @@ -28,6 +29,7 @@ import com.yoho.search.models.SearchApiResult;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -342,9 +344,9 @@ public class SelectionsForPc extends AbstractCacheAbleService {
IAggregation standardAggregation = aggregationFactoryService.getStandardAggregation(paramMap);
Object standardResponse = this.getResponseByIAggregation(standardAggregation, preAggregationResult, aggMaps);
if (standardResponse != null) {
Iterator<Map.Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
Iterator<Entry<String, Object>> entryStandard = ((Map<String, Object>) standardResponse).entrySet().iterator();
while (entryStandard.hasNext()) {
Map.Entry<String, Object> entry = entryStandard.next();
Entry<String, Object> entry = entryStandard.next();
if (paramMap.containsKey(entry.getKey())) {
filter.put(entry.getKey(), entry.getValue());
} else {
... ... @@ -397,9 +399,9 @@ public class SelectionsForPc extends AbstractCacheAbleService {
}
private boolean getNLSMap(MultiBucketsAggregation aggregation) {
Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator();
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
while (itAgg.hasNext()) {
MultiBucketsAggregation.Bucket bucket = itAgg.next();
Bucket bucket = itAgg.next();
// String bool = bucket.getKexy();
String bool = bucket.getKeyAsString();
if ("Y".equals(bool)) {
... ...
... ... @@ -27,11 +27,13 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
... ... @@ -71,9 +73,9 @@ public class ShopListService {
}
queryBuilder.minimumShouldMatch("100%");
// 2.1 全球购得分减半
FunctionScoreQueryBuilder.FilterFunctionBuilder[] filterFunctionBuilders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[2];
filterFunctionBuilders[0] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));
filterFunctionBuilders[1] = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f));
FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[2];
filterFunctionBuilders[0] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"), ScoreFunctionBuilders.weightFactorFunction(0.5f));
filterFunctionBuilders[1] = new FilterFunctionBuilder(QueryBuilders.termQuery(ProductIndexEsField.csBrandKeyword, keyword), ScoreFunctionBuilders.weightFactorFunction(10f));
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder, filterFunctionBuilders);
functionScoreQueryBuilder.boostMode(CombineFunction.MULTIPLY);
searchParam.setQuery(functionScoreQueryBuilder);
... ... @@ -144,10 +146,10 @@ public class ShopListService {
* @return
*/
private List<Map<String, Object>> getShopList(final MultiBucketsAggregation aggregation) {
Iterator<? extends MultiBucketsAggregation.Bucket> itAgg = aggregation.getBuckets().iterator();
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
List<Map<String, Object>> productSourceList = new ArrayList<Map<String, Object>>();
while (itAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itAgg.next();
Bucket lt = itAgg.next();
if (lt.getAggregations().getAsMap().containsKey("product")) {
TopHits topHits = lt.getAggregations().get("product");
productSourceList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits));
... ...