...
|
...
|
@@ -5,6 +5,8 @@ import java.util.Arrays; |
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
...
|
...
|
@@ -17,8 +19,12 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.service.base.SearchCacheService;
|
...
|
...
|
@@ -41,6 +47,23 @@ public abstract class AbstractRecallService { |
|
|
private SearchServiceHelper searchServiceHelper;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private SearchCacheFactory searchCacheFactory;
|
|
|
|
|
|
private SearchCache searchCache;
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
searchCache = searchCacheFactory.getRecallCache();
|
|
|
}
|
|
|
|
|
|
private List<SearchParam> getSearchpaParams(List<RecallSearchParam> recallSearchParams) {
|
|
|
List<SearchParam> results = new ArrayList<SearchParam>();
|
|
|
for (RecallSearchParam recallSearchParam : recallSearchParams) {
|
|
|
results.add(recallSearchParam.getSearchParam());
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0、召回skns以及总数
|
...
|
...
|
@@ -59,36 +82,47 @@ public abstract class AbstractRecallService { |
|
|
List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys);
|
|
|
logger.info("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 3、执行查询
|
|
|
// 3、缓存中获取
|
|
|
List<SearchParam> searchParams = this.getSearchpaParams(recallSearchParams);
|
|
|
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
|
|
|
if (jsonObject != null) {
|
|
|
return JSON.toJavaObject(jsonObject, RecallProductSknList.class);
|
|
|
}
|
|
|
|
|
|
// 4、查询
|
|
|
begin = System.currentTimeMillis();
|
|
|
RecallResult recallResult = this.queryRecallResult(recallSearchParams);
|
|
|
logger.info("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 4、从兜底策略中获取总数
|
|
|
// 5、从兜底策略中获取总数
|
|
|
long total = this.getTotalFromRecallResult(recallResult);
|
|
|
|
|
|
// 5、粗排
|
|
|
// 6、粗排
|
|
|
begin = System.currentTimeMillis();
|
|
|
recallResult = this.doSketchyRank(paramMap, recallResult);
|
|
|
logger.info("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 6、精排
|
|
|
// 7、精排
|
|
|
begin = System.currentTimeMillis();
|
|
|
recallResult = this.doCarefulRank(paramMap, recallResult);
|
|
|
logger.info("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 7、重排
|
|
|
// 8、重排
|
|
|
begin = System.currentTimeMillis();
|
|
|
recallResult = this.doReRank(paramMap, recallResult);
|
|
|
logger.info("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 8、构造返回结果
|
|
|
// 9、构造返回结果
|
|
|
begin = System.currentTimeMillis();
|
|
|
List<Integer> productSknList = new ArrayList<Integer>();
|
|
|
for (Map<String, Object> product : recallResult.getProductList()) {
|
|
|
productSknList.add(MapUtils.getInteger(product, ProductIndexEsField.productSkn));
|
|
|
}
|
|
|
return new RecallProductSknList(total, productSknList);
|
|
|
RecallProductSknList recallProductSknList = new RecallProductSknList(total, productSknList);
|
|
|
// 10、加入缓存
|
|
|
searchCacheService.addJSONObjectToCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams, (JSONObject) JSON.toJSON(recallProductSknList));
|
|
|
return recallProductSknList;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|