Authored by hugufei

fix bug

... ... @@ -56,6 +56,17 @@ public class SearchCacheFactory {
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getPagePersionalFactorCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 60;
return this.getOrCreateSearchCache("PAGE_PERSIONAL_FACTOR", cacheType, cacheInMinute);
}
/**
* 获取默认的搜索缓存
*
* @return
... ...
... ... @@ -96,7 +96,7 @@ public class EhCache implements CacheInterface {
Collection<Element> elements = new ArrayList<>();
for (Map.Entry<RedisKeyBuilder, ? extends String> entry: map.entrySet()) {
Element element = new Element(entry.getKey().getKey(), entry.getValue());
element.setTimeToLive(timeoutInSecond * 60 * 60 );
element.setTimeToLive(timeoutInSecond);
elements.add(element);
}
cache.putAll(elements);
... ...
... ... @@ -128,8 +128,7 @@ public class ExtendFilterHelper {
BoolQueryBuilder filter = QueryBuilders.boolQuery();
//must
filter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, sortPriceArea.getMiddleSortId()));
//TODO REPLACE gender WITH PriceArea
filter.must(QueryBuilders.termQuery(ProductIndexEsField.gender, sortPriceArea.getPriceArea()));
filter.must(QueryBuilders.termQuery(ProductIndexEsField.priceArea, sortPriceArea.getPriceArea()));
//must not
filter.mustNot(forbiddenFlowFilter());
return filter;
... ...
... ... @@ -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;
... ...
... ... @@ -32,7 +32,7 @@ public class SortPriceStrategy implements IStrategy {
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getHeatValueDescSort();
return SortBuilderHelper.getRandomSort();
}
@Override
... ...