Authored by 胡古飞

搜索支持将某个SKN展示到第一个

... ... @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import com.yoho.search.service.personalized.PersonalizedSearch;
import com.yoho.search.service.service.SearchDynamicConfigService;
import com.yoho.search.service.utils.SearchRequestParams;
@Component
public class FunctionScoreSearchHelper {
... ... @@ -29,9 +30,14 @@ public class FunctionScoreSearchHelper {
private WeightBuilder genWeightFactorBuilder(float factor) {
return ScoreFunctionBuilders.weightFactorFunction(factor);
}
public QueryBuilder buildFunctionScoreQueryBuild(QueryBuilder queryBuilder, Map<String, String> paramMap) {
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
// 将某个SKN展示到第一个
if (searchCommonHelper.isFirstProductSknSearch(paramMap)) {
functionScoreQueryBuilder.add(QueryBuilders.termQuery("productSkn", paramMap.get(SearchRequestParams.FIRST_PRODUCRSKN)),
ScoreFunctionBuilders.weightFactorFunction(1000));
}
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
personalizedSearch.addPersonalizedUserFetureFactor(functionScoreQueryBuilder, paramMap);
personalizedSearch.addPersonalizedFieldValueFactor(functionScoreQueryBuilder, paramMap);
... ...
... ... @@ -59,6 +59,23 @@ public class SearchCommonHelper {
}
return true;
}
/**
* 是否需要对某个SKN加分
* @param paramMap
* @return
*/
public boolean isFirstProductSknSearch(Map<String, String> paramMap){
String first_productskn = paramMap.get(SearchRequestParams.FIRST_PRODUCRSKN);
if(StringUtils.isBlank(first_productskn)){
return false;
}
String order = paramMap.get("order");
if(!StringUtils.isBlank(order)){
return false;
}
return true;
}
/**
* 是否需要对品牌降分
... ...
... ... @@ -30,7 +30,7 @@ public class SearchSortHelper {
void init() {
orderValues.add("_score:desc");
orderValues.add("_score:asc");
orderValues.add("id:desc");
orderValues.add("id:asc");
... ... @@ -93,7 +93,7 @@ public class SearchSortHelper {
} else {
realSortField = CharUtils.underlineToCamelhump(realSortField);
}
if(realSortField.equalsIgnoreCase("score")){
if (realSortField.equalsIgnoreCase("score")) {
realSortField = "_score";
}
realOrder.append("," + realSortField + ":" + sortParts[1]);
... ... @@ -115,7 +115,6 @@ public class SearchSortHelper {
filteredFieldNames.add(fieldName);
sortBuilders.add(SortBuilders.fieldSort(fieldName).order(sortOrder));
}
/**
* 是否需要优先按分数排序
... ... @@ -136,11 +135,15 @@ public class SearchSortHelper {
if (searchCommonHelper.isNeedDeScoreBrandSearch(paramMap)) {
return true;
}
// 4、传了需要显示第一个SKN的参数过来时
if (searchCommonHelper.isFirstProductSknSearch(paramMap)) {
return true;
}
return false;
}
// 都要添加次要排序条件
private void addDeafultSortBuildSorts(List<SortBuilder> sortBuilders,List<String> filteredFieldNames) {
private void addDeafultSortBuildSorts(List<SortBuilder> sortBuilders, List<String> filteredFieldNames) {
this.addSortBuildSorts(sortBuilders, filteredFieldNames, "firstShelveTime", SortOrder.DESC);
this.addSortBuildSorts(sortBuilders, filteredFieldNames, "id", SortOrder.DESC);
}
... ...
... ... @@ -78,6 +78,7 @@ public class SearchRequestParams {
public static final String SHOPS_PARAM_ISGLOBAL = "isGlobal";
public static final String PARAM_SEARCH_PROMOTIONID = "newPromotionId";
public static final String FIRST_PRODUCRSKN = "firstProductSkn";
}
... ...