...
|
...
|
@@ -6,8 +6,10 @@ 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.core.personalized.models.SortPriceArea;
|
|
|
import com.yoho.search.core.personalized.models.UserPersionalFactorRsp;
|
|
|
import com.yoho.search.recall.scene.models.ParamQueryFilter;
|
|
|
import com.yoho.search.recall.scene.models.PersionalFactor;
|
|
|
import com.yoho.search.recall.scene.models.PagePersionalFactor;
|
|
|
import com.yoho.search.service.base.SearchCacheService;
|
|
|
import com.yoho.search.service.base.SearchCommonService;
|
|
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
...
|
...
|
@@ -47,7 +49,7 @@ class PagePersionalFactorComponent { |
|
|
* @param paramQueryFilter
|
|
|
* @return
|
|
|
*/
|
|
|
public PersionalFactor queryPagePersionalFactor(ParamQueryFilter paramQueryFilter) {
|
|
|
public PagePersionalFactor queryPagePersionalFactor(ParamQueryFilter paramQueryFilter) {
|
|
|
//0、构造参数
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setQuery(paramQueryFilter.getParamQuery());
|
...
|
...
|
@@ -67,9 +69,9 @@ class PagePersionalFactorComponent { |
|
|
|
|
|
//3、缓存中获取
|
|
|
String cacheKey = searchCacheService.genSearchParamString(ISearchConstants.INDEX_NAME_PRODUCT_INDEX,searchParam);
|
|
|
PersionalFactor pagePersionalFactor = searchCacheService.getSerializableObjectFromCache(searchCache,cacheKey,PersionalFactor.class,true);
|
|
|
if(pagePersionalFactor!=null) {
|
|
|
return pagePersionalFactor;
|
|
|
PagePersionalFactor pagePagePersionalFactor = searchCacheService.getSerializableObjectFromCache(searchCache,cacheKey,PagePersionalFactor.class,true);
|
|
|
if(pagePagePersionalFactor !=null) {
|
|
|
return pagePagePersionalFactor;
|
|
|
}
|
|
|
|
|
|
//4、执行查询
|
...
|
...
|
@@ -78,11 +80,11 @@ class PagePersionalFactorComponent { |
|
|
//5、构造结果
|
|
|
Map<String, Aggregation> aggregationMap = searchResult.getAggMaps();
|
|
|
List<Integer> brandIds = this.getBrandIdsFromAggregationMap(aggregationMap);
|
|
|
List<PersionalFactor.SortPriceArea> sortPriceAreas = this.getSortPriceAreasFromAggregationMap(aggregationMap);
|
|
|
pagePersionalFactor = new PersionalFactor(brandIds, sortPriceAreas,null);
|
|
|
List<SortPriceArea> sortPriceAreas = this.getSortPriceAreasFromAggregationMap(aggregationMap);
|
|
|
pagePagePersionalFactor = new PagePersionalFactor(brandIds, sortPriceAreas);
|
|
|
//6、加入缓存
|
|
|
searchCacheService.addSerializableObjectToCache(searchCache,cacheKey,pagePersionalFactor,true);
|
|
|
return pagePersionalFactor;
|
|
|
searchCacheService.addSerializableObjectToCache(searchCache,cacheKey, pagePagePersionalFactor,true);
|
|
|
return pagePagePersionalFactor;
|
|
|
}
|
|
|
|
|
|
private List<Integer> getBrandIdsFromAggregationMap(Map<String, Aggregation> aggregationMap) {
|
...
|
...
|
@@ -100,8 +102,8 @@ class PagePersionalFactorComponent { |
|
|
return brandIds;
|
|
|
}
|
|
|
|
|
|
private List<PersionalFactor.SortPriceArea> getSortPriceAreasFromAggregationMap(Map<String, Aggregation> aggregationMap) {
|
|
|
List<PersionalFactor.SortPriceArea> sortPrices = new ArrayList<>();
|
|
|
private List<SortPriceArea> getSortPriceAreasFromAggregationMap(Map<String, Aggregation> aggregationMap) {
|
|
|
List<SortPriceArea> sortPrices = new ArrayList<>();
|
|
|
MultiBucketsAggregation aggregation = (MultiBucketsAggregation) aggregationMap.get("middleSortIdAgg");
|
|
|
if (aggregation == null) {
|
|
|
return new ArrayList<>();
|
...
|
...
|
@@ -119,7 +121,7 @@ class PagePersionalFactorComponent { |
|
|
while (priceAreaIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket genderBucket = priceAreaIterator.next();
|
|
|
Integer priceArea = Integer.valueOf(genderBucket.getKeyAsString());
|
|
|
sortPrices.add(new PersionalFactor.SortPriceArea(middleSortId, priceArea));
|
|
|
sortPrices.add(new SortPriceArea(middleSortId, priceArea));
|
|
|
}
|
|
|
}
|
|
|
return sortPrices;
|
...
|
...
|
|