|
|
package com.yoho.search.service.service.helper;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
...
|
...
|
@@ -32,30 +30,10 @@ public class FunctionScoreSearchHelper { |
|
|
|
|
|
static float globalWeight = 0.50f;
|
|
|
|
|
|
static float deScoreFieldWeight = 0.2f;
|
|
|
|
|
|
private WeightBuilder genWeightFactorBuilder(float factor) {
|
|
|
return ScoreFunctionBuilders.weightFactorFunction(factor);
|
|
|
}
|
|
|
|
|
|
private String[] getStringArrayFromParam(Map<String, String> paramMap, String paramName, boolean isNumic) {
|
|
|
String paramValue = paramMap.get(paramName);
|
|
|
if (StringUtils.isBlank(paramValue)) {
|
|
|
return null;
|
|
|
}
|
|
|
String[] values = paramValue.split(",");
|
|
|
if (!isNumic) {
|
|
|
return values;
|
|
|
}
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
for (String value : values) {
|
|
|
if (StringUtils.isNumeric(value)) {
|
|
|
results.add(value);
|
|
|
}
|
|
|
}
|
|
|
return results.toArray(new String[results.size()]);
|
|
|
}
|
|
|
|
|
|
public QueryBuilder buildFunctionScoreQueryBuild(QueryBuilder queryBuilder, Map<String, String> paramMap) {
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
|
|
|
// 将某个SKN展示到第一个
|
...
|
...
|
@@ -80,27 +58,6 @@ public class FunctionScoreSearchHelper { |
|
|
functionScoreQueryBuilder.add(physicalChannelQueryBuilder, ScoreFunctionBuilders.weightFactorFunction(physicalChannelWeight));
|
|
|
}
|
|
|
}
|
|
|
// 对某些属性降分【为了兼容,下个版本去除】
|
|
|
if (searchCommonHelper.isNeedDeScoreSomeFiled(paramMap)) {
|
|
|
// 对性别降分
|
|
|
String[] deScoreGenders = this.getStringArrayFromParam(paramMap, SearchRequestParams.DESOCRE_GENDER, false);
|
|
|
if (deScoreGenders != null && deScoreGenders.length > 0) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("gender", deScoreGenders), ScoreFunctionBuilders.weightFactorFunction(deScoreFieldWeight));
|
|
|
}
|
|
|
// 对年龄层降分
|
|
|
String[] deScoreAgelevels = this.getStringArrayFromParam(paramMap, SearchRequestParams.DESOCRE_AGELEVEL, false);
|
|
|
if (deScoreAgelevels != null && deScoreAgelevels.length > 0) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("ageLevel", deScoreAgelevels), ScoreFunctionBuilders.weightFactorFunction(deScoreFieldWeight));
|
|
|
}
|
|
|
// 对非小分类降分
|
|
|
String[] notSmallSortId = this.getStringArrayFromParam(paramMap, SearchRequestParams.DESOCRE_NOT_SORT, true);
|
|
|
if (notSmallSortId != null && notSmallSortId.length > 0) {
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery("smallSortId", notSmallSortId);
|
|
|
boolQueryBuilder.mustNot(termsQueryBuilder);
|
|
|
functionScoreQueryBuilder.add(boolQueryBuilder, ScoreFunctionBuilders.weightFactorFunction(deScoreFieldWeight));
|
|
|
}
|
|
|
}
|
|
|
functionScoreQueryBuilder.boostMode(CombineFunction.MULT);
|
|
|
return functionScoreQueryBuilder;
|
|
|
}
|
...
|
...
|
@@ -145,7 +102,7 @@ public class FunctionScoreSearchHelper { |
|
|
if (StringUtils.isNotBlank(query) && (query.contains("男") || query.contains("女"))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_GENDER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER))){
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_GENDER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER))) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
...
|
...
|
|