Authored by 胡古飞

add function score for physical_channel

... ... @@ -90,5 +90,24 @@ public class SearchDynamicConfigService {
public boolean deScoreFieldOpen() {
return configReader.getBoolean("search.degrade.open.descorefield", true);
}
/**
* 频道降分是否打开
*
* @return
*/
public boolean isDeScoreForChannelOpen() {
return configReader.getBoolean("search.degrade.descore.channel.open", true);
}
/**
* 频道降分权重
*
* @return
*/
public double getDeScoreForChannelWeight() {
return configReader.getDouble("search.degrade.descore.channel.value", 0.6);
}
}
... ...
... ... @@ -38,18 +38,18 @@ public class FunctionScoreSearchHelper {
return ScoreFunctionBuilders.weightFactorFunction(factor);
}
private String[] getStringArrayFromParam(Map<String, String> paramMap, String paramName,boolean isNumic){
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){
String[] values = paramValue.split(",");
if (!isNumic) {
return values;
}
List<String> results = new ArrayList<String>();
List<String> results = new ArrayList<String>();
for (String value : values) {
if(StringUtils.isNumeric(value)){
if (StringUtils.isNumeric(value)) {
results.add(value);
}
}
... ... @@ -72,7 +72,14 @@ public class FunctionScoreSearchHelper {
if (searchCommonHelper.isNeedDeScoreBrandSearch(paramMap)) {
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isForbiddenSortBrand", "1"), ScoreFunctionBuilders.weightFactorFunction(0));
}
// 对某些属性降分
// 针对频道降分
if (searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
QueryBuilder physicalChannelQueryBuilder = this.getPhysicalChannelQueryBuilder(paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL));
if (physicalChannelQueryBuilder != null) {
functionScoreQueryBuilder.add(physicalChannelQueryBuilder, ScoreFunctionBuilders.weightFactorFunction((float) dynamicConfig.getDeScoreForChannelWeight()));
}
}
// 对某些属性降分【为了兼容,下个版本去除】
if (searchCommonHelper.isNeedDeScoreSomeFiled(paramMap)) {
// 对性别降分
String[] deScoreGenders = this.getStringArrayFromParam(paramMap, SearchRequestParams.DESOCRE_GENDER, false);
... ... @@ -97,4 +104,32 @@ public class FunctionScoreSearchHelper {
return functionScoreQueryBuilder;
}
private QueryBuilder getPhysicalChannelQueryBuilder(String physicalChannel) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
TermsQueryBuilder physicalChannelsTermsQueryBuilder = QueryBuilders.termsQuery("physicalChannels", physicalChannel);
// 男生频道,对非男生频道的商品或者性别女的降分
if (physicalChannel.equals("1")) {
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "2"));
return boolQueryBuilder;
}
// 女生频道,对非女生频道的商品或者性别男的降分
if (physicalChannel.equals("2")) {
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "1"));
return boolQueryBuilder;
}
// 潮童频道,对非潮童频道的或成人的商品降分
if (physicalChannel.equals("3")) {
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
boolQueryBuilder.should(QueryBuilders.termsQuery("ageLevel", "1"));
return boolQueryBuilder;
}
// 创意生活频道,对非创意生活频道的商品降分
if (physicalChannel.equals("4")) {
return boolQueryBuilder.mustNot(physicalChannelsTermsQueryBuilder);
}
return null;
}
}
... ...
... ... @@ -108,6 +108,26 @@ public class SearchCommonHelper {
}
return false;
}
/**
* 是否需要对频道降分
*
* @param paramMap
* @return
*/
public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
String physicalChannel = paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL);
if(StringUtils.isBlank(physicalChannel)){
return false;
}
if(!isFuzzySearchDefault(paramMap)){
return false;
}
if(dynamicConfig.isDeScoreForChannelOpen()){
return false;
}
return true;
}
/**
* 是否需要对某些字段降分
... ...
... ... @@ -87,5 +87,7 @@ public class SearchRequestParams {
public static final String DESOCRE_GENDER = "descoreGender";
public static final String DESOCRE_AGELEVEL = "descoreAgeLevel";
public static final String DESOCRE_NOT_SORT = "descoreNotSort";
public static final String PHYSICAL_CHANNEL = "physical_channel";
}
... ...