...
|
...
|
@@ -8,6 +8,9 @@ import com.yoho.search.common.SearchCommonService; |
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.models.aggregations.AggKeyCount;
|
|
|
import com.yoho.search.models.aggregations.AggKeyCountTwoLevel;
|
|
|
import com.yoho.search.service.helper.AggCommonHelper;
|
|
|
import com.yoho.search.service.helper.SearchParamHelper;
|
|
|
import com.yoho.search.service.recall.helper.ExtendFilterHelper;
|
|
|
import com.yoho.search.models.recall.ParamQueryFilter;
|
...
|
...
|
@@ -78,12 +81,12 @@ public class QueryPageFactorBaseService extends AbstractCacheComponent<PagePerso |
|
|
filter.must(old.getFiter());
|
|
|
filter.mustNot(ExtendFilterHelper.notRecallFilter());//聚合的时候带上不召回的数据
|
|
|
searchParam.setFiter(filter);
|
|
|
|
|
|
searchParam.setSize(0);
|
|
|
|
|
|
//2、构造聚合参数
|
|
|
List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<>();
|
|
|
aggregationBuilders.add(brandSortAggBuilder());//品类-品牌聚合
|
|
|
aggregationBuilders.add(addScorePoolIdsBuilder());//商品池聚合
|
|
|
searchParam.setAggregationBuilders(aggregationBuilders);
|
|
|
|
|
|
//3、执行查询
|
...
|
...
|
@@ -91,10 +94,15 @@ public class QueryPageFactorBaseService extends AbstractCacheComponent<PagePerso |
|
|
|
|
|
//4、构造结果
|
|
|
Map<String, Aggregation> aggregationMap = searchResult.getAggMaps();
|
|
|
List<Integer> addScorePoolIds = this.genAddScorePoolIds(aggregationMap);
|
|
|
List<SortBrand> sortBrands = this.getBrandSortsFromAggregationMap(aggregationMap);
|
|
|
List<Integer> misortIds = this.getMisortIds(sortBrands);
|
|
|
List<Integer> brandIds = this.getBrandIds(sortBrands);
|
|
|
return new PagePersonalFactor(misortIds, brandIds, sortBrands);
|
|
|
return new PagePersonalFactor(misortIds, brandIds, sortBrands,addScorePoolIds);
|
|
|
}
|
|
|
|
|
|
private List<Integer> genAddScorePoolIds(Map<String, Aggregation> aggregationMap) {
|
|
|
return AggCommonHelper.getIdsFromAggMaps(aggregationMap,"addScorePoolIdsAgg");
|
|
|
}
|
|
|
|
|
|
private List<Integer> getMisortIds(List<SortBrand> sortBrands) {
|
...
|
...
|
@@ -136,59 +144,80 @@ public class QueryPageFactorBaseService extends AbstractCacheComponent<PagePerso |
|
|
return middleSortAggBuilder;
|
|
|
}
|
|
|
|
|
|
private List<SortBrand> getBrandSortsFromAggregationMap(Map<String, Aggregation> aggregationMap) {
|
|
|
Map<Integer, List<Integer>> brand2MiSortIdsMap = this.getValueFromAggregationMap(aggregationMap, "sortBrandBrandIdAgg", "sortBrandMiddleSortAgg");
|
|
|
List<SortBrand> pageBrandSorts = new ArrayList<>();
|
|
|
for (Map.Entry<Integer, List<Integer>> entry : brand2MiSortIdsMap.entrySet()) {
|
|
|
Integer brandId = entry.getKey();
|
|
|
List<Integer> misorts = entry.getValue();
|
|
|
for (Integer misort : misorts) {
|
|
|
pageBrandSorts.add(new SortBrand(misort, brandId));
|
|
|
}
|
|
|
}
|
|
|
return pageBrandSorts;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从聚合结果中获取参数,仅支持二层聚合
|
|
|
* skn-商品池
|
|
|
*
|
|
|
* @param aggregationMap
|
|
|
* @param firstAggName
|
|
|
* @param secondAggName
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, List<Integer>> getValueFromAggregationMap(Map<String, Aggregation> aggregationMap, String firstAggName, String secondAggName) {
|
|
|
Map<Integer, List<Integer>> aggResultMap = new HashMap<>();
|
|
|
if (!aggregationMap.containsKey(firstAggName)) {
|
|
|
return aggResultMap;
|
|
|
}
|
|
|
MultiBucketsAggregation firstAggregation = (MultiBucketsAggregation) aggregationMap.get(firstAggName);
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> firstAggregationIterator = firstAggregation.getBuckets().iterator();
|
|
|
while (firstAggregationIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket firstAggregationBucket = firstAggregationIterator.next();
|
|
|
Integer firstAggregationBucketKey = Integer.valueOf(firstAggregationBucket.getKeyAsString());
|
|
|
Map<String, Aggregation> secondAggregationMap = firstAggregationBucket.getAggregations().asMap();
|
|
|
if (secondAggregationMap == null || !secondAggregationMap.containsKey(secondAggName)) {
|
|
|
continue;
|
|
|
}
|
|
|
List<Integer> secondAggregationBucketKeys = this.getAggValuesFromMultiBucketsAggregation((MultiBucketsAggregation) secondAggregationMap.get(secondAggName));
|
|
|
aggResultMap.put(firstAggregationBucketKey, secondAggregationBucketKeys);
|
|
|
}
|
|
|
return aggResultMap;
|
|
|
private TermsAggregationBuilder addScorePoolIdsBuilder() {
|
|
|
TermsAggregationBuilder addScorePoolIdsAggBuilder = AggregationBuilders.terms("addScorePoolIdsAgg").field(ProductIndexEsField.toAddScorePoolIds).size(20);
|
|
|
return addScorePoolIdsAggBuilder;
|
|
|
}
|
|
|
|
|
|
private List<Integer> getAggValuesFromMultiBucketsAggregation(MultiBucketsAggregation aggregation) {
|
|
|
List<Integer> results = new ArrayList<>();
|
|
|
if (aggregation == null) {
|
|
|
return results;
|
|
|
}
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> bucketsIterator = aggregation.getBuckets().iterator();
|
|
|
while (bucketsIterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket bucket = bucketsIterator.next();
|
|
|
Integer value = Integer.valueOf(bucket.getKeyAsString());
|
|
|
results.add(value);
|
|
|
private List<SortBrand> getBrandSortsFromAggregationMap(Map<String, Aggregation> aggregationMap) {
|
|
|
List<AggKeyCountTwoLevel> results = AggCommonHelper.getAggKeyCountTwoLevelList(aggregationMap,"sortBrandBrandIdAgg","sortBrandMiddleSortAgg");
|
|
|
List<SortBrand> pageBrandSorts = new ArrayList<>();
|
|
|
for (AggKeyCountTwoLevel aggKeyCountTwoLevel : results) {
|
|
|
Integer brandId = aggKeyCountTwoLevel.getFirstAggKeyCount().getKey();
|
|
|
List<AggKeyCount> misortInfos = aggKeyCountTwoLevel.getSecondAggKeyCountList();
|
|
|
for (AggKeyCount misortInfo : misortInfos) {
|
|
|
pageBrandSorts.add(new SortBrand(misortInfo.getKey(), brandId));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
return pageBrandSorts;
|
|
|
|
|
|
// Map<Integer, List<Integer>> brand2MiSortIdsMap = this.getValueFromAggregationMap(aggregationMap, "sortBrandBrandIdAgg", "sortBrandMiddleSortAgg");
|
|
|
// List<SortBrand> pageBrandSorts = new ArrayList<>();
|
|
|
// for (Map.Entry<Integer, List<Integer>> entry : brand2MiSortIdsMap.entrySet()) {
|
|
|
// Integer brandId = entry.getKey();
|
|
|
// List<Integer> misorts = entry.getValue();
|
|
|
// for (Integer misort : misorts) {
|
|
|
// pageBrandSorts.add(new SortBrand(misort, brandId));
|
|
|
// }
|
|
|
// }
|
|
|
// return pageBrandSorts;
|
|
|
}
|
|
|
|
|
|
// /**
|
|
|
// * 从聚合结果中获取参数,仅支持二层聚合
|
|
|
// *
|
|
|
// * @param aggregationMap
|
|
|
// * @param firstAggName
|
|
|
// * @param secondAggName
|
|
|
// * @return
|
|
|
// */
|
|
|
// private Map<Integer, List<Integer>> getValueFromAggregationMap(Map<String, Aggregation> aggregationMap, String firstAggName, String secondAggName) {
|
|
|
// Map<Integer, List<Integer>> aggResultMap = new HashMap<>();
|
|
|
// if (!aggregationMap.containsKey(firstAggName)) {
|
|
|
// return aggResultMap;
|
|
|
// }
|
|
|
// MultiBucketsAggregation firstAggregation = (MultiBucketsAggregation) aggregationMap.get(firstAggName);
|
|
|
// Iterator<? extends MultiBucketsAggregation.Bucket> firstAggregationIterator = firstAggregation.getBuckets().iterator();
|
|
|
// while (firstAggregationIterator.hasNext()) {
|
|
|
// MultiBucketsAggregation.Bucket firstAggregationBucket = firstAggregationIterator.next();
|
|
|
// Integer firstAggregationBucketKey = Integer.valueOf(firstAggregationBucket.getKeyAsString());
|
|
|
// Map<String, Aggregation> secondAggregationMap = firstAggregationBucket.getAggregations().asMap();
|
|
|
// if (secondAggregationMap == null || !secondAggregationMap.containsKey(secondAggName)) {
|
|
|
// continue;
|
|
|
// }
|
|
|
// List<Integer> secondAggregationBucketKeys = this.getAggValuesFromMultiBucketsAggregation((MultiBucketsAggregation) secondAggregationMap.get(secondAggName));
|
|
|
// aggResultMap.put(firstAggregationBucketKey, secondAggregationBucketKeys);
|
|
|
// }
|
|
|
// return aggResultMap;
|
|
|
// }
|
|
|
//
|
|
|
// private List<Integer> getAggValuesFromMultiBucketsAggregation(MultiBucketsAggregation aggregation) {
|
|
|
// List<Integer> results = new ArrayList<>();
|
|
|
// if (aggregation == null) {
|
|
|
// return results;
|
|
|
// }
|
|
|
// Iterator<? extends MultiBucketsAggregation.Bucket> bucketsIterator = aggregation.getBuckets().iterator();
|
|
|
// while (bucketsIterator.hasNext()) {
|
|
|
// MultiBucketsAggregation.Bucket bucket = bucketsIterator.next();
|
|
|
// Integer value = Integer.valueOf(bucket.getKeyAsString());
|
|
|
// results.add(value);
|
|
|
// }
|
|
|
// return results;
|
|
|
// }
|
|
|
|
|
|
} |
...
|
...
|
|