...
|
...
|
@@ -3,6 +3,9 @@ package com.yoho.search.service.scene.productanalysis; |
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
import com.google.common.cache.CacheLoader;
|
|
|
import com.google.common.cache.LoadingCache;
|
|
|
import com.yoho.search.base.helper.RnnVectorCalculator;
|
|
|
import com.yoho.search.base.helper.Word2VectorCalculator;
|
|
|
import com.yoho.search.base.utils.*;
|
...
|
...
|
@@ -16,6 +19,7 @@ import com.yoho.search.models.SortGroup; |
|
|
import com.yoho.search.models.aggregations.AggKeyCount;
|
|
|
import com.yoho.search.models.aggregations.AggKeyCountTwoLevel;
|
|
|
import com.yoho.search.service.aggregations.AggregationsService;
|
|
|
import com.yoho.search.service.aggregations.impls.ProductAnalysisDateAggregation;
|
|
|
import com.yoho.search.service.aggregations.impls.ProductAnalysisShopAggregation;
|
|
|
import com.yoho.search.service.aggregations.impls.ProductAnalysisSortAggregation;
|
|
|
import com.yoho.search.service.aggregations.impls.ShopBrandAggregation;
|
...
|
...
|
@@ -26,6 +30,7 @@ import com.yoho.search.service.scene.activity.recommendshop.ActivityShopBrand; |
|
|
import com.yoho.search.service.scene.general.SortGroupService;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
...
|
...
|
@@ -36,6 +41,7 @@ import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -52,6 +58,42 @@ public class RecommendOnProductAnalysisService { |
|
|
private BrandVectorCacheBean brandVectorCacheBean;
|
|
|
@Autowired
|
|
|
private SortGroupService sortGroupService;
|
|
|
//Guava Cache
|
|
|
|
|
|
private LoadingCache<String, List<String>> dateRange = CacheBuilder.newBuilder()
|
|
|
.maximumSize(30000)
|
|
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
|
|
.build(new CacheLoader<String, List<String>>() {
|
|
|
public List<String> load(String key) {
|
|
|
return getDateRange();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
private List<String> getDateRange() {
|
|
|
IAggregation aggregation = new ProductAnalysisDateAggregation();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setQuery(QueryBuilders.matchAllQuery());
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(aggregation.getBuilder()));
|
|
|
try {
|
|
|
JSONObject aggResult = aggregationsService.getAggNameAndResponse(aggregation, searchParam, ISearchConstants.INDEX_NAME_YOHO_PRODUCT_ANALYSIS);
|
|
|
if (aggResult != null && !CollectionUtils.isEmpty(aggResult.getJSONArray(aggregation.aggName()))) {
|
|
|
List<String> dateList = JSON.parseArray(JSON.toJSONString(aggResult.get(aggregation.aggName())), String.class);
|
|
|
if (dateList.size() != 2 || StringUtils.isBlank(dateList.get(0)) || StringUtils.isBlank(dateList.get(1))) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
return dateList;
|
|
|
}
|
|
|
}catch (Exception e) {
|
|
|
LOGGER.error(e.getMessage(), e);
|
|
|
}
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
private boolean isAfterSixOclock() {
|
|
|
Date sixOclock = DateUtils.truncate(DateUtils.setHours(new Date(), 6), Calendar.HOUR);
|
|
|
return new Date().compareTo(sixOclock) > 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
public SearchApiResult recommendSort(Map<String, String> paramMap) {
|
...
|
...
|
@@ -108,12 +150,13 @@ public class RecommendOnProductAnalysisService { |
|
|
List<Integer> shopIds = new ArrayList<>();
|
|
|
try {
|
|
|
addDefaultParamsToParamMap(paramMapClone);
|
|
|
JSONObject aggResult = aggregationsService.getShopAggregationResult(paramMapClone, 8);
|
|
|
JSONObject aggResult = aggregationsService.getShopAggregationResultWithOrderByShopCreateTime(paramMapClone, 20);
|
|
|
if (aggResult != null && !CollectionUtils.isEmpty(aggResult.getJSONArray("shopAgg"))) {
|
|
|
JSONArray shopList = aggResult.getJSONArray("shopAgg");
|
|
|
for (Object shop : shopList) {
|
|
|
shopIds.add(((JSONObject)shop).getInteger("shop_id"));
|
|
|
}
|
|
|
shopIds = SearchCollectionUtils.safeSubList(shopIds, 0, 8);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error(e.getMessage(), e);
|
...
|
...
|
@@ -200,7 +243,7 @@ public class RecommendOnProductAnalysisService { |
|
|
JSONObject jsonObject = aggregationsService.getAggNameAndResponseWithCache(aggregation, searchParam, ISearchConstants.INDEX_NAME_YOHO_PRODUCT_ANALYSIS);
|
|
|
List<Integer> aggShopIds = new ArrayList<>();
|
|
|
if (jsonObject != null && jsonObject.get(aggregation.aggName()) != null) {
|
|
|
aggShopIds = JSON.parseArray(jsonObject.toJSONString(jsonObject.get(aggregation.aggName())), Integer.class);
|
|
|
aggShopIds = JSON.parseArray(JSON.toJSONString(jsonObject.get(aggregation.aggName())), Integer.class);
|
|
|
}
|
|
|
return aggShopIds;
|
|
|
}
|
...
|
...
|
@@ -213,7 +256,7 @@ public class RecommendOnProductAnalysisService { |
|
|
JSONObject jsonObject = aggregationsService.getAggNameAndResponseWithCache(aggregation, searchParam);
|
|
|
List<AggKeyCountTwoLevel> aggKeyCountTwoLevels = new ArrayList<>();
|
|
|
if (jsonObject != null && jsonObject.get(aggregation.aggName()) != null) {
|
|
|
aggKeyCountTwoLevels = JSON.parseArray(jsonObject.toJSONString(jsonObject.get(aggregation.aggName())), AggKeyCountTwoLevel.class);
|
|
|
aggKeyCountTwoLevels = JSON.parseArray(JSON.toJSONString(jsonObject.get(aggregation.aggName())), AggKeyCountTwoLevel.class);
|
|
|
}
|
|
|
return aggKeyCountTwoLevels;
|
|
|
}
|
...
|
...
|
@@ -359,7 +402,7 @@ public class RecommendOnProductAnalysisService { |
|
|
JSONObject jsonObject = aggregationsService.getAggNameAndResponseWithCache(aggregation, searchParam, ISearchConstants.INDEX_NAME_YOHO_PRODUCT_ANALYSIS);
|
|
|
List<Integer> aggSortIds = new ArrayList<>();
|
|
|
if (jsonObject != null && jsonObject.get(aggregation.aggName()) != null) {
|
|
|
aggSortIds = JSON.parseArray(jsonObject.toJSONString(jsonObject.get(aggregation.aggName())), Integer.class);
|
|
|
aggSortIds = JSON.parseArray(JSON.toJSONString(jsonObject.get(aggregation.aggName())), Integer.class);
|
|
|
}
|
|
|
return aggSortIds;
|
|
|
}
|
...
|
...
|
@@ -405,6 +448,18 @@ public class RecommendOnProductAnalysisService { |
|
|
addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.PARAM_SEARCH_GENDER, ProductIndexEsField.gender);
|
|
|
addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.PARAM_SEARCH_YH_CHANNEL, "yhChannel");
|
|
|
addMustDoubleRangeQuery(boolFilter, paramMap, SearchRequestParams.PARAM_SEARCH_SHELVETIME, ProductIndexEsField.shelveTime);
|
|
|
try {
|
|
|
List<String> day_date = dateRange.get("DAY_DATE");
|
|
|
if (!CollectionUtils.isEmpty(day_date)) {
|
|
|
if (isAfterSixOclock()) {
|
|
|
boolFilter.must(QueryBuilders.rangeQuery("dayDate").gte(day_date.get(0)).lte(day_date.get(0)));
|
|
|
} else {
|
|
|
boolFilter.must(QueryBuilders.rangeQuery("dayDate").gte(day_date.get(1)).lte(day_date.get(1)));
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setQuery(queryBuilder);
|
...
|
...
|
|