...
|
...
|
@@ -2,59 +2,38 @@ package com.yoho.search.service.recall.config; |
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.Transfer;
|
|
|
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.dal.model.CsRecallConfigSortBrand;
|
|
|
import com.yoho.search.service.recall.models.personal.PagePersonalFactor;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Component
|
|
|
class ConfigSortBrandService {
|
|
|
|
|
|
private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL");
|
|
|
class ConfigSortBrandService extends AbstractCacheConfigBean<CsRecallConfigSortBrand, SortBrand> {
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
private List<SortBrand> configSortBrandsCache = new ArrayList<>();
|
|
|
|
|
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
schedule.scheduleAtFixedRate(() -> loadConfigSortBrandsCache(), 0, 1, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
private void loadConfigSortBrandsCache() {
|
|
|
try {
|
|
|
RECALL_NEW_LOGGER.info("loadConfigSortBrandsCache begin ........");
|
|
|
long begin = System.currentTimeMillis();
|
|
|
List<SortBrand> tempCache = new ArrayList<>();
|
|
|
List<CsRecallConfigSortBrand> csRecallConfigSortBrands = queryAll();
|
|
|
for (CsRecallConfigSortBrand csRecallConfigSortBrand : csRecallConfigSortBrands) {
|
|
|
@Override
|
|
|
protected Transfer<CsRecallConfigSortBrand, SortBrand> getTransfer() {
|
|
|
return new Transfer<CsRecallConfigSortBrand, SortBrand>() {
|
|
|
@Override
|
|
|
public SortBrand transfer(CsRecallConfigSortBrand csRecallConfigSortBrand) {
|
|
|
Integer misort = csRecallConfigSortBrand.getSortId();
|
|
|
Integer brandId = csRecallConfigSortBrand.getBrandId();
|
|
|
tempCache.add(new SortBrand(misort, brandId));
|
|
|
return new SortBrand(misort, brandId);
|
|
|
}
|
|
|
configSortBrandsCache = tempCache;
|
|
|
RECALL_NEW_LOGGER.info("loadConfigSortBrandsCache success,configSortBrandsCache size is[{}], cost is[{}] ", configSortBrandsCache.size(), System.currentTimeMillis() - begin);
|
|
|
} catch (Exception e) {
|
|
|
RECALL_NEW_LOGGER.error("loadConfigSortBrandsCache error,exception is:" + e.getMessage(), e);
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
private List<CsRecallConfigSortBrand> queryAll(){
|
|
|
@Override
|
|
|
protected List<CsRecallConfigSortBrand> queryAllFromEs() {
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(10000);
|
...
|
...
|
@@ -62,22 +41,26 @@ class ConfigSortBrandService { |
|
|
List<Map<String, Object>> results = searchResult.getResultList();
|
|
|
List<CsRecallConfigSortBrand> list = new ArrayList<>();
|
|
|
for (Map<String, Object> result : results) {
|
|
|
list.add(JSON.parseObject(JSON.toJSONString(result),CsRecallConfigSortBrand.class));
|
|
|
list.add(JSON.parseObject(JSON.toJSONString(result), CsRecallConfigSortBrand.class));
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 随机获取size个品类品牌
|
|
|
* 随机获取页面中,属于配置的品牌品类
|
|
|
*
|
|
|
* @param pageFactor
|
|
|
* @param pageSortBrandKeys
|
|
|
* @param filterSortBrandKeys
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
private List<SortBrand> randomConfigSortBrands(List<SortBrand> configSortBrands, Set<String> pageSortBrandKeys, Set<String> filterSortBrandKeys, int size) {
|
|
|
List<SortBrand> copyList = new ArrayList<>(configSortBrands);
|
|
|
Collections.shuffle(copyList);
|
|
|
public List<SortBrand> randomConfigSortBrand(PagePersonalFactor pageFactor, Set<String> pageSortBrandKeys, Set<String> filterSortBrandKeys, int size) {
|
|
|
if (size <= 0) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<SortBrand> copyList = this.getCopyCacheListAndRandom();
|
|
|
List<SortBrand> results = new ArrayList<>();
|
|
|
for (SortBrand sortBrand : copyList) {
|
|
|
if (results.size() >= size) {
|
...
|
...
|
@@ -91,23 +74,8 @@ class ConfigSortBrandService { |
|
|
}
|
|
|
results.add(sortBrand);
|
|
|
}
|
|
|
System.out.println(JSON.toJSONString(results));
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 随机获取页面中,属于配置的品牌品类
|
|
|
*
|
|
|
* @param pageFactor
|
|
|
* @param pageSortBrandKeys
|
|
|
* @param filterSortBrandKeys
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public List<SortBrand> queryConfigSortBrand(PagePersonalFactor pageFactor, Set<String> pageSortBrandKeys, Set<String> filterSortBrandKeys, int size) {
|
|
|
if (size <= 0) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
return this.randomConfigSortBrands(this.configSortBrandsCache, pageSortBrandKeys, filterSortBrandKeys, size);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|