Authored by wangnan

Merge branch 'master' into wn_photoSearch

... ... @@ -535,6 +535,7 @@ public class SearchExplainerService {
}
SearchParam searchParam = new SearchParam();
searchParam.setQuery(QueryBuilders.termQuery("productSkn", skn));
searchParam.setSize(1);
SearchResult searchResult = client.search(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (searchResult == null || searchResult.getResultList() == null || searchResult.getResultList().isEmpty()) {
throw new RuntimeException("product skn not exist");
... ...
... ... @@ -29,7 +29,9 @@ public class ProductIndexBaseService {
productIndexExcludeFields.add("specialSearchField*");
productIndexExcludeFields.add("*Keyword");
productIndexExcludeFields.add("standard*");
productIndexExcludeFields.add("*Ids");
productIndexExcludeFields.add(ProductIndexEsField.poolId);
productIndexExcludeFields.add(ProductIndexEsField.pools);
productIndexExcludeFields.add(ProductIndexEsField.activities);
... ...
... ... @@ -53,6 +53,8 @@ public class FunctionScoreSearchHelper {
private static final FirstShelveTimeScore COMMON_FIRST_SHELVE_SCORE = new FirstShelveTimeScore(30, 7, 23);
// 新品到着的个性化时间维度
private static final FirstShelveTimeScore NEW_REC_FIRST_SHELVE_SCORE = new FirstShelveTimeScore(4, 1, 3);
// 模糊搜索的个性化时间维度
private static final FirstShelveTimeScore FUZZY_FIRST_SHELVE_SCORE= new FirstShelveTimeScore(90, 60, 30);
private static final float BRAND_INCREASE_SCORE_WEIGHT = 1.1f;// 品类列表默认针对某些品牌加分
private static final float BRAND_SORT_INCREASE_SCORE_WEIGHT = 1.1f; // 针对特定的【品牌+品类】加分
... ... @@ -109,7 +111,9 @@ public class FunctionScoreSearchHelper {
// 3、针对首次上架时间打分
if (searchCommonHelper.isNewRecPageDefault(paramMap)) {
this.addFirstShelveTimeScore(functionScoreQueryBuilder, getNewArrivalPageShelveTimeScore());
} else {
} else if (searchCommonHelper.isFuzzySearchPageDefault(paramMap)) {
this.addFirstShelveTimeScore(functionScoreQueryBuilder, FUZZY_FIRST_SHELVE_SCORE);
}else {
this.addFirstShelveTimeScore(functionScoreQueryBuilder, getOtherPageShelveTimeScore());
}
// 4、针对断码率高的商品降分
... ...
package com.yoho.search.service.service.helper;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.service.SearchDynamicConfigService;
import com.yoho.search.service.utils.SearchRequestParams;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
... ... @@ -12,9 +11,11 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.service.SearchDynamicConfigService;
import com.yoho.search.service.utils.SearchRequestParams;
@Component
public class SearchCommonHelper {
... ... @@ -131,7 +132,7 @@ public class SearchCommonHelper {
* @param keyword
* @return
*/
public boolean isQuerySkn(String keyword) {
public boolean isQuerySknOrSku(String keyword) {
try {
String key = "";
if (keyword.contains(" ")) {
... ... @@ -141,7 +142,7 @@ public class SearchCommonHelper {
} else if (keyword.contains("+")) {
key = keyword.split("\\+")[0];
}
if ((CharUtils.isNumeric(keyword) && keyword.length() >= 7) || (CharUtils.isNumeric(key) && key.length() >= 7)) {
if ((CharUtils.isNumeric(keyword) && keyword.length() >= 6) || (CharUtils.isNumeric(key) && key.length() >= 6)) {
return true;
}
return false;
... ...
... ... @@ -63,10 +63,12 @@ public class SearchServiceHelper {
queryBuilder.type(multiMatchQueryBuilderType);
}
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
if (searchCommonHelper.isQuerySkn(query)) {
// 3.如果查询的是skn或skuIds,则走productSkn_ansj和skuIds这个字段
if (searchCommonHelper.isQuerySknOrSku(query)) {
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
queryBuilder.field(ProductIndexEsField.skuIds);
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
queryBuilder.minimumShouldMatch("1");
return queryBuilder;
}
... ... @@ -98,50 +100,11 @@ public class SearchServiceHelper {
}
/**
* 构造关键字查询的query的时候operator默认为or,minimum匹配度是50%
*
* @param paramMap
* @return
*/
QueryBuilder constructOrQueryBuilder(Map<String, String> paramMap) {
// 0、处理查询关键字
String query = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);
if (StringUtils.isBlank(query)) {
return QueryBuilders.matchAllQuery();
}
paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, query);
// 1、处理查询中包含性别的情况
searchCommonHelper.dealKeywordOfGender(query, paramMap);
// 2、构建多字段匹配【keyword需要有一个默认的查询字段以及权重设置,就可以拼接成一个sql】
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(query);
MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = searchCommonHelper.getMultiMatchQueryBuilderType();
if (multiMatchQueryBuilderType != null) {
queryBuilder.type(multiMatchQueryBuilderType);
}
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
if (searchCommonHelper.isQuerySkn(query)) {
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
return queryBuilder;
}
// 4.设置查询字段和比重【AND表示多字段都要匹配,可提高精确度】
this.setDefaultSearchField(queryBuilder, paramMap);
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
queryBuilder.minimumShouldMatch("75%");
return queryBuilder;
}
/**
* 设置默认搜索字段(字段+权重)
*
* @param queryBuilder
*/
public void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, Map<String, String> paramMap) {
private void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, Map<String, String> paramMap) {
List<String> fields = ISearchConstants.SEARCH_DEFAULT_FIELD;
for (String field : fields) {
String[] fieldBoost = field.split("\\^");
... ...
... ... @@ -122,7 +122,7 @@ public class ProductListServiceImpl implements IProductListService {
// 4)记录关键字对应的查询结果
String queryWord = paramMap.get("query");
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySkn(queryWord)) {
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
searchKeyWordService.recordKeyWordByResultCount(queryWord, searchResult.getTotal());
}
... ... @@ -150,7 +150,7 @@ public class ProductListServiceImpl implements IProductListService {
// 1. 判断是否需要进行term推荐
// 1.1 query不为空
String queryWord = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySkn(queryWord))) {
if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySknOrSku(queryWord))) {
return false;
}
... ...
... ... @@ -111,7 +111,7 @@ public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyS
// 4)记录关键字对应的查询结果
String queryWord = paramMap.get("query");
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySkn(queryWord)) {
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
searchKeyWordService.recordKeyWordByResultCount(queryWord, searchResult.getTotal());
}
... ...
... ... @@ -433,7 +433,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
if (checkStr.startsWith("skn")) {
checkStr = checkStr.substring("skn".length()).trim();
}
return searchCommonHelper.isQuerySkn(checkStr);
return searchCommonHelper.isQuerySknOrSku(checkStr);
}
private JSONObject defaultSuggestRecommendation() {
... ...
... ... @@ -74,7 +74,7 @@ public class FuzzySceneService extends AbstractSceneService {
this.addSuggestion(searchApiResult, paramMap);
// 4、模糊搜索页记录关键字对应的查询结果
String queryWord = paramMap.get("query");
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySkn(queryWord)) {
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
long total = ((JSONObject) searchApiResult.getData()).getLongValue("total");
searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
}
... ... @@ -115,7 +115,7 @@ public class FuzzySceneService extends AbstractSceneService {
// 1. 判断是否需要进行term推荐
// 1.1 query不为空
String queryWord = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySkn(queryWord))) {
if (StringUtils.isEmpty(queryWord) || (queryWord.length() > 30 && !searchCommonHelper.isQuerySknOrSku(queryWord))) {
return;
}
// 1.2不是第一页直接不返回
... ...