...
|
...
|
@@ -277,56 +277,63 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
List<Integer> getUserLikeBrandIds(String uid, Map<String, String> paramMap) {
|
|
|
String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
|
|
|
String userVectorFeature = bigDataRedisService.getUserBrandVectorFeature(uid, vectorFeatureVersion);
|
|
|
if (StringUtils.isBlank(vectorFeatureVersion) || StringUtils.isBlank(userVectorFeature)) {
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
// 1、设置filter
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
// 过滤大分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_MAXSORT)) {
|
|
|
int[] maxsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("maxSortIds", maxsortids));
|
|
|
}
|
|
|
// 过滤中分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_MIDDLESORT)) {
|
|
|
int[] middlesortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("middleSortIds", middlesortids));
|
|
|
}
|
|
|
// 过滤小分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_SMALLSORT)) {
|
|
|
int[] smallsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortIds", smallsortids));
|
|
|
}
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortIds", Arrays.asList("383", "375", "461", "463")));
|
|
|
private List<Integer> getUserLikeBrandIds(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
String uid = MapUtils.getString(paramMap, "uid", "0");
|
|
|
String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
|
|
|
String userVectorFeature = bigDataRedisService.getUserBrandVectorFeature(uid, vectorFeatureVersion);
|
|
|
if (StringUtils.isBlank(vectorFeatureVersion) || StringUtils.isBlank(userVectorFeature)) {
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
// 1、设置filter
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
// 过滤大分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_MAXSORT)) {
|
|
|
int[] maxsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("maxSortIds", maxsortids));
|
|
|
}
|
|
|
// 过滤中分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_MIDDLESORT)) {
|
|
|
int[] middlesortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("middleSortIds", middlesortids));
|
|
|
}
|
|
|
// 过滤小分类
|
|
|
if (this.checkParamNotFiltered(paramMap, null, SearchRequestParams.PARAM_SEARCH_SMALLSORT)) {
|
|
|
int[] smallsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT), ",");
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortIds", smallsortids));
|
|
|
}
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortIds", Arrays.asList("383", "375", "461", "463")));
|
|
|
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
// 2、设置query
|
|
|
Map<String, Object> scriptParams = new HashMap<>();
|
|
|
scriptParams.put("field", "brandFeature");
|
|
|
scriptParams.put("userFeatureFactors", userVectorFeature);
|
|
|
scriptParams.put("vectorFeatureVersion", vectorFeatureVersion);
|
|
|
scriptParams.put("baseConstant", "1.0");
|
|
|
scriptParams.put("factorConstant", "1.0");
|
|
|
Script script = new Script(ScriptType.INLINE, "native", "feature_factor_vector_score", scriptParams);
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(ScoreFunctionBuilders.scriptFunction(script));
|
|
|
searchParam.setQuery(functionScoreQueryBuilder);
|
|
|
// 3、设置order
|
|
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.scoreSort().order(SortOrder.DESC)));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(10);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
// 2、设置query
|
|
|
Map<String, Object> scriptParams = new HashMap<>();
|
|
|
scriptParams.put("field", "brandFeature");
|
|
|
scriptParams.put("userFeatureFactors", userVectorFeature);
|
|
|
scriptParams.put("vectorFeatureVersion", vectorFeatureVersion);
|
|
|
scriptParams.put("baseConstant", "1.0");
|
|
|
scriptParams.put("factorConstant", "1.0");
|
|
|
Script script = new Script(ScriptType.INLINE, "native", "feature_factor_vector_score", scriptParams);
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(ScoreFunctionBuilders.scriptFunction(script));
|
|
|
searchParam.setQuery(functionScoreQueryBuilder);
|
|
|
// 3、设置order
|
|
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.scoreSort().order(SortOrder.DESC)));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(10);
|
|
|
|
|
|
// 4、查询es
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
List<Map<String, Object>> results = searchResult.getResultList();
|
|
|
List<Integer> brandIds = new ArrayList<Integer>();
|
|
|
for (Map<String, Object> result : results) {
|
|
|
brandIds.add(MapUtils.getInteger(result, "id"));
|
|
|
// 4、查询es
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
List<Map<String, Object>> results = searchResult.getResultList();
|
|
|
List<Integer> brandIds = new ArrayList<Integer>();
|
|
|
for (Map<String, Object> result : results) {
|
|
|
brandIds.add(MapUtils.getInteger(result, "id"));
|
|
|
}
|
|
|
logger.warn("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
|
|
|
return brandIds;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
return brandIds;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -340,8 +347,8 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
List<IRecallStrategy> recallStrategy = new ArrayList<IRecallStrategy>();
|
|
|
int pageSize = this.getPageSize(paramMap);
|
|
|
// 0、获取用户偏好品牌
|
|
|
//List<Integer> brandIds = this.getUserGlobalBrandIds(paramMap);
|
|
|
List<Integer> brandIds = this.getUserGlobalBrandIds(paramMap);
|
|
|
|
|
|
// 1、支持firstProductSkn的召回
|
|
|
recallStrategy.add(new FirstProductSknStrategy(1, this.getFirstProductSkns(paramMap)));
|
|
|
// 2、支持直通车的召回
|
...
|
...
|
|