Authored by 胡古飞

找相似代码优化

package com.yoho.search.service.servicenew.impl;
package com.yoho.search.service.service.helper;
import java.util.ArrayList;
import java.util.Arrays;
... ... @@ -20,38 +20,26 @@ import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.service.SearchCacheService;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.AggProductListHelper;
import com.yoho.search.service.service.helper.FunctionScoreSearchHelper;
import com.yoho.search.service.service.helper.SearchCommonHelper;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.service.helper.SearchSortHelper;
import com.yoho.search.service.vo.SearchFieldBoost;
@Component
public class SearchLikeCommonService {
public class SearchLikeHelper {
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SearchServiceHelper searchServiceHelper;
@Autowired
private SearchSortHelper searchSortHelper;
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private FunctionScoreSearchHelper functionScoreSearchHelper;
@Autowired
private AggProductListHelper aggProductListHelper;
public List<SearchFieldBoost> searchFieldBoosts = new ArrayList<SearchFieldBoost>();
private int sortMaxBoost = 1000;
private int brandMaxBoost = 700;
private int brandMaxBoost = 400;
private int productNameMaxBoost = 600;
private int standardOnlyNamesBoost = 500;
private int otherBoost = 150;
private int standardOnlyNamesBoost = 700;
private int otherBoost = 200;
private void addSearchFieldBoost(List<String> searchFields, float maxBoost) {
float boost = maxBoost;
... ...
... ... @@ -25,6 +25,7 @@ import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.AggProductListHelper;
import com.yoho.search.service.service.helper.FunctionScoreSearchHelper;
import com.yoho.search.service.service.helper.SearchCommonHelper;
import com.yoho.search.service.service.helper.SearchLikeHelper;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.service.helper.SearchSortHelper;
import com.yoho.search.service.servicenew.ISearchLikeInShopService;
... ... @@ -49,7 +50,7 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
@Autowired
private AggProductListHelper aggProductListHelper;
@Autowired
private SearchLikeCommonService searchLikeCommonService;
private SearchLikeHelper searchLikeHelper;
public boolean isLegalInteger(Integer id) {
if (id != null && id > 0) {
... ... @@ -66,7 +67,7 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
return new SearchApiResult().setCode(400).setMessage("请输入SKN");
}
// 2、获取当前查询的SKN的基本信息
JSONObject productInfoInEs = searchLikeCommonService.getProductInfoInEs(productSkn);
JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);
if (productInfoInEs == null) {
return new SearchApiResult().setCode(400).setMessage("SKN不存在");
}
... ... @@ -90,11 +91,11 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
String brandName = productInfoInEs.getString("brandName");
String productFeatureFactor = productInfoInEs.getString("productFeatureFactor");
String query = brandName + "," + productName + "," + standardOnlyNames + "," + style;
QueryBuilder queryBuilder = searchLikeCommonService.genSearchLikeQueryBuilder(query, "40%", productFeatureFactor);
QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(query, "40%", productFeatureFactor);
searchParam.setQuery(queryBuilder);
// 5、设置filter
BoolQueryBuilder boolFilter = searchLikeCommonService.genDefaultQueryBuilder(Arrays.asList(productSkn));
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(Arrays.asList(productSkn));
Integer brandId = productInfoInEs.getInteger("brandId");
Integer shopId = productInfoInEs.getInteger("shopId");
if (isLegalInteger(shopId)) {
... ... @@ -131,7 +132,7 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
jsonObject.put("page_total", 1);
jsonObject.put("page_size", pageSize);
jsonObject.put("total", productList.size());
jsonObject.put("product_info", searchLikeCommonService.genProductInfoResult(productInfoInEs));
jsonObject.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));
jsonObject.put("product_list", productList);
searchCacheService.addJSONObjectToCache(cacheEnum, productIndexName, searchParam, jsonObject);
return new SearchApiResult().setData(jsonObject);
... ...
... ... @@ -33,6 +33,7 @@ import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.AggProductListHelper;
import com.yoho.search.service.service.helper.FunctionScoreSearchHelper;
import com.yoho.search.service.service.helper.SearchCommonHelper;
import com.yoho.search.service.service.helper.SearchLikeHelper;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.service.helper.SearchSortHelper;
import com.yoho.search.service.servicenew.ISearchLikeService;
... ... @@ -57,7 +58,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
@Autowired
private AggProductListHelper aggProductListHelper;
@Autowired
private SearchLikeCommonService searchLikeCommonService;
private SearchLikeHelper searchLikeHelper;
@Override
public SearchApiResult searchLike(Map<String, String> paramMap) {
... ... @@ -67,7 +68,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
return new SearchApiResult().setCode(400).setMessage("请输入SKN");
}
// 2、获取当前查询的SKN的基本信息
JSONObject productInfoInEs = searchLikeCommonService.getProductInfoInEs(productSkn);
JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);
if (productInfoInEs == null) {
return new SearchApiResult().setCode(400).setMessage("SKN不存在");
}
... ... @@ -103,7 +104,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
dataMap.put("page_total", 1);
dataMap.put("page_size", pageSize);
dataMap.put("total", productList.size());
dataMap.put("product_info", searchLikeCommonService.genProductInfoResult(productInfoInEs));
dataMap.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));
dataMap.put("product_list", productList);
return new SearchApiResult().setData(dataMap);
}
... ... @@ -233,7 +234,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
if (!isInBrand) {
minimumShouldMatch = "40%";
}
return searchLikeCommonService.genSearchLikeQueryBuilder(query, minimumShouldMatch, productFeatureFactor);
return searchLikeHelper.genSearchLikeQueryBuilder(query, minimumShouldMatch, productFeatureFactor);
}
private List<String> getGenderInfo(String gender) {
... ... @@ -247,7 +248,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
}
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand) {
BoolQueryBuilder boolFilter = searchLikeCommonService.genDefaultQueryBuilder(notProductSkns);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns);
// 1)设置此SKN相关的过滤条件
String gender = productInfoInEs.getString("gender");
List<String> genderList = this.getGenderInfo(gender);
... ...