...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.search.recall.scene.persional; |
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.common.cache.SearchCacheFactory;
|
|
|
import com.yoho.search.common.cache.model.SearchCache;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.recall.scene.models.ParamQueryFilter;
|
...
|
...
|
@@ -18,6 +19,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
...
|
...
|
@@ -33,6 +35,13 @@ class PersionalFactorPageComponent { |
|
|
@Autowired
|
|
|
private SearchCacheFactory searchCacheFactory;
|
|
|
|
|
|
private SearchCache searchCache;
|
|
|
|
|
|
@PostConstruct
|
|
|
void init(){
|
|
|
searchCache = searchCacheFactory.getPagePersionalFactorCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取链接中的个性化因子
|
|
|
*
|
...
|
...
|
@@ -52,14 +61,14 @@ class PersionalFactorPageComponent { |
|
|
|
|
|
//2、品类价格带聚合
|
|
|
TermsAggregationBuilder middleAggBuilder = AggregationBuilders.terms("middleSortIdAgg").field(ProductIndexEsField.middleSortId).size(100);
|
|
|
TermsAggregationBuilder genderAggBuilder = AggregationBuilders.terms("genderAgg").field(ProductIndexEsField.gender).size(5);
|
|
|
TermsAggregationBuilder genderAggBuilder = AggregationBuilders.terms("priceAreaAgg").field(ProductIndexEsField.priceArea).size(7);
|
|
|
middleAggBuilder.subAggregation(genderAggBuilder);
|
|
|
aggregationBuilders.add(middleAggBuilder);//品类性格聚合
|
|
|
searchParam.setAggregationBuilders(aggregationBuilders);
|
|
|
|
|
|
//3、缓存中获取
|
|
|
String cacheKey = searchCacheService.genSearchParamString(ISearchConstants.INDEX_NAME_PRODUCT_INDEX,searchParam);
|
|
|
PersionalFactor pagePersionalFactor = searchCacheService.getSerializableObjectFromCache(searchCacheFactory.getAggregationSearchCache(),cacheKey,PersionalFactor.class,true);
|
|
|
PersionalFactor pagePersionalFactor = searchCacheService.getSerializableObjectFromCache(searchCache,cacheKey,PersionalFactor.class,true);
|
|
|
if(pagePersionalFactor!=null) {
|
|
|
return pagePersionalFactor;
|
|
|
}
|
...
|
...
|
@@ -83,9 +92,9 @@ class PersionalFactorPageComponent { |
|
|
if (aggregation == null) {
|
|
|
return brandIds;
|
|
|
}
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> iteratorterator = aggregation.getBuckets().iterator();
|
|
|
while (iteratorterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket bucket = iteratorterator.next();
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> brandIdIterator = aggregation.getBuckets().iterator();
|
|
|
while (brandIdIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket bucket = brandIdIterator.next();
|
|
|
Integer brandId = Integer.valueOf(bucket.getKeyAsString());
|
|
|
brandIds.add(brandId);
|
|
|
}
|
...
|
...
|
@@ -103,15 +112,15 @@ class PersionalFactorPageComponent { |
|
|
MultiBucketsAggregation.Bucket middleSortIdBucket = iterator.next();
|
|
|
Integer middleSortId = Integer.valueOf(middleSortIdBucket.getKeyAsString());
|
|
|
|
|
|
MultiBucketsAggregation genderAggregation = ((MultiBucketsAggregation) middleSortIdBucket.getAggregations().asMap().get("genderAgg"));
|
|
|
if(genderAggregation==null){
|
|
|
MultiBucketsAggregation priceAreaAggregation = ((MultiBucketsAggregation) middleSortIdBucket.getAggregations().asMap().get("priceAreaAgg"));
|
|
|
if(priceAreaAggregation==null){
|
|
|
continue;
|
|
|
}
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> genderIterator = genderAggregation.getBuckets().iterator();
|
|
|
while (genderIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket genderBucket = genderIterator.next();
|
|
|
Integer gender = Integer.valueOf(genderBucket.getKeyAsString());
|
|
|
sortPrices.add(new PersionalFactor.SortPriceArea(middleSortId, gender));
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> priceAreaIterator = priceAreaAggregation.getBuckets().iterator();
|
|
|
while (priceAreaIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket genderBucket = priceAreaIterator.next();
|
|
|
Integer priceArea = Integer.valueOf(genderBucket.getKeyAsString());
|
|
|
sortPrices.add(new PersionalFactor.SortPriceArea(middleSortId, priceArea));
|
|
|
}
|
|
|
}
|
|
|
return sortPrices;
|
...
|
...
|
|