Authored by unknown

fix

@@ -4,6 +4,7 @@ import java.util.Map; @@ -4,6 +4,7 @@ import java.util.Map;
4 4
5 import javax.servlet.http.HttpServletRequest; 5 import javax.servlet.http.HttpServletRequest;
6 6
  7 +import com.yoho.search.service.base.SearchDynamicConfigService;
7 import com.yoho.search.service.scene.searchlike.BigdataSimilarSknService; 8 import com.yoho.search.service.scene.searchlike.BigdataSimilarSknService;
8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Controller; 10 import org.springframework.stereotype.Controller;
@@ -40,6 +41,8 @@ public class SearchLikeSecneController { @@ -40,6 +41,8 @@ public class SearchLikeSecneController {
40 private ISimilarProductService similarProductService; 41 private ISimilarProductService similarProductService;
41 @Autowired 42 @Autowired
42 private BigdataSimilarSknService bigdataSimilarSknService; 43 private BigdataSimilarSknService bigdataSimilarSknService;
  44 + @Autowired
  45 + private SearchDynamicConfigService searchDynamicConfigService;
43 46
44 @RequestMapping(method = RequestMethod.GET, value = "/searchLike") 47 @RequestMapping(method = RequestMethod.GET, value = "/searchLike")
45 @ResponseBody 48 @ResponseBody
@@ -59,8 +62,10 @@ public class SearchLikeSecneController { @@ -59,8 +62,10 @@ public class SearchLikeSecneController {
59 @ResponseBody 62 @ResponseBody
60 public SearchApiResult searchLikeNotInShop(HttpServletRequest request) { 63 public SearchApiResult searchLikeNotInShop(HttpServletRequest request) {
61 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); 64 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
62 -// return searchLikeNotInShopService.searchLikeNotInShop(paramMap);  
63 - return bigdataSimilarSknService.searchLikeSimilarSknNotInShop(paramMap); 65 + if (searchDynamicConfigService.isSearchLikeSimilarSknOpen()) {
  66 + return bigdataSimilarSknService.searchLikeSimilarSknNotInShop(paramMap);
  67 + }
  68 + return searchLikeNotInShopService.searchLikeNotInShop(paramMap);
64 } 69 }
65 70
66 /** 71 /**
@@ -208,5 +208,12 @@ public class SearchDynamicConfigService { @@ -208,5 +208,12 @@ public class SearchDynamicConfigService {
208 public boolean isRecommendPersionalOpen() { 208 public boolean isRecommendPersionalOpen() {
209 return configReader.getBoolean("search.persional.recommend.open", true); 209 return configReader.getBoolean("search.persional.recommend.open", true);
210 } 210 }
  211 +
  212 + /**
  213 + * 找相似是否使用bigdatasimilarskn
  214 + */
  215 + public boolean isSearchLikeSimilarSknOpen() {
  216 + return configReader.getBoolean("search.searchlike.similarskn", true);
  217 + }
211 218
212 } 219 }
@@ -28,15 +28,13 @@ import java.util.List; @@ -28,15 +28,13 @@ import java.util.List;
28 import java.util.Map; 28 import java.util.Map;
29 29
30 @Service 30 @Service
31 -public class BigdataSimilarSknService extends SearchLikeNotInShopService{ 31 +public class BigdataSimilarSknService {
32 private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknService.class); 32 private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknService.class);
33 33
34 @Autowired 34 @Autowired
35 private SearchLikeHelper searchLikeHelper; 35 private SearchLikeHelper searchLikeHelper;
36 @Autowired 36 @Autowired
37 private ProductIndexBaseService productIndexBaseService; 37 private ProductIndexBaseService productIndexBaseService;
38 - @Autowired  
39 - private SearchDynamicConfigService searchDynamicConfigService;  
40 38
41 public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) { 39 public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) {
42 try { 40 try {
@@ -65,10 +63,7 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ @@ -65,10 +63,7 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
65 List<String> diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(",")); 63 List<String> diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(","));
66 searchParams.add(builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, pageSize/3)); 64 searchParams.add(builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, pageSize/3));
67 } 65 }
68 -  
69 - int sameSortCount = searchDynamicConfigService.getSearchLikeNotInShopSameSortPercent() * pageSize / 100;  
70 - searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), sameSortCount, true));  
71 - searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize - sameSortCount, false)); 66 + searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize, true));
72 67
73 // 4、获取搜索结果[截取条数] 68 // 4、获取搜索结果[截取条数]
74 List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams); 69 List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
@@ -95,11 +90,65 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ @@ -95,11 +90,65 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
95 } 90 }
96 } 91 }
97 92
  93 + private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
  94 + // 1、设置SearchParam
  95 + SearchParam searchParam = new SearchParam();
  96 + // 2)设置query和filter
  97 + searchParam.setQuery(builderQueryBuilder(productInfoInEs, inSameSort ? "30%" : "20%"));
  98 + searchParam.setFiter(builderFilterBuilder(productInfoInEs, productSkns, inSameSort));
  99 + // 3、设置排序规则[按打分排序]
  100 + List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
  101 + sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
  102 + searchParam.setSortBuilders(sortBuilders);
  103 + // 4、设置分页参数
  104 + searchParam.setOffset(0);
  105 + searchParam.setSize(pageSize);
  106 + // 5)设置返回的参数【节省带宽】
  107 + List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
  108 + searchParam.setIncludeFields(includeFields);
  109 + return searchParam;
  110 + }
  111 +
  112 + private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) {
  113 + String queryString = searchLikeHelper.genYohoQueryStringWithOutBrandName(productInfoInEs);
  114 + String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor);
  115 + QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor);
  116 + return queryBuilder;
  117 + }
  118 +
  119 + private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSameSort) {
  120 + String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
  121 + boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
  122 + BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
  123 + // 1)设置此SKN相关的性别过滤条件
  124 + String gender = productInfoInEs.getString(ProductIndexEsField.gender);
  125 + List<String> genderList = searchLikeHelper.getGenderInfo(gender);
  126 + if (genderList != null && !genderList.isEmpty()) {
  127 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
  128 + }
  129 + // 2)设置品牌或店铺信息
  130 + Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
  131 + Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
  132 + if (searchLikeHelper.isLegalInteger(shopId)) {
  133 + boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId));
  134 + } else if (searchLikeHelper.isLegalInteger(brandId)) {
  135 + boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
  136 + }
  137 + // 3)设置品类信息
  138 + Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
  139 + if (inSameSort) {
  140 + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
  141 + } else {
  142 + boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
  143 + boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.smallSort_smallSort_keyword, productInfoInEs.getString(ProductIndexEsField.smallSort)));// 有些小分类同名,要排除这种情况。
  144 + }
  145 + return boolFilter;
  146 + }
  147 +
98 private SearchParam builderSimilarSknSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) { 148 private SearchParam builderSimilarSknSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
99 // 1、设置SearchParam 149 // 1、设置SearchParam
100 SearchParam searchParam = new SearchParam(); 150 SearchParam searchParam = new SearchParam();
101 // 2)设置query和filter 151 // 2)设置query和filter
102 - searchParam.setQuery(builderSimilarSknQueryBuilder(productInfoInEs));  
103 searchParam.setFiter(builderSimilarSknFilterBuilder(productInfoInEs, productSkns)); 152 searchParam.setFiter(builderSimilarSknFilterBuilder(productInfoInEs, productSkns));
104 // 3、设置排序规则[按打分排序] 153 // 3、设置排序规则[按打分排序]
105 List<SortBuilder<?>> sortBuilders = new ArrayList<>(); 154 List<SortBuilder<?>> sortBuilders = new ArrayList<>();
@@ -139,8 +188,4 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ @@ -139,8 +188,4 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
139 return boolFilter; 188 return boolFilter;
140 } 189 }
141 190
142 - private QueryBuilder builderSimilarSknQueryBuilder(JSONObject productInfoInEs) {  
143 - return searchLikeHelper.genProductFeatureQueryBuilder( productInfoInEs.getString(ProductIndexEsField.productFeatureFactor));  
144 - }  
145 -  
146 } 191 }
@@ -100,7 +100,7 @@ public class SearchLikeNotInShopService{ @@ -100,7 +100,7 @@ public class SearchLikeNotInShopService{
100 } 100 }
101 } 101 }
102 102
103 - protected SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) { 103 + private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
104 // 1、设置SearchParam 104 // 1、设置SearchParam
105 SearchParam searchParam = new SearchParam(); 105 SearchParam searchParam = new SearchParam();
106 // 2)设置query和filter 106 // 2)设置query和filter
@@ -49,6 +49,8 @@ search.persional.rateLimit.open=true @@ -49,6 +49,8 @@ search.persional.rateLimit.open=true
49 search.persional.newstrategy.open=false 49 search.persional.newstrategy.open=false
50 search.persional.recommend.open=true 50 search.persional.recommend.open=true
51 51
  52 +#searchlike
  53 +search.searchlike.similarskn=true
52 54
53 search.persional.rateLimit.brand.productList=200:2 55 search.persional.rateLimit.brand.productList=200:2
54 search.persional.rateLimit.brand.aggregations=100:2 56 search.persional.rateLimit.brand.aggregations=100:2