Authored by 胡古飞

fix SearchRecommendServiceImpl

@@ -7,12 +7,16 @@ import org.slf4j.LoggerFactory; @@ -7,12 +7,16 @@ import org.slf4j.LoggerFactory;
7 7
8 import com.yoho.search.base.utils.HttpServletRequestUtils; 8 import com.yoho.search.base.utils.HttpServletRequestUtils;
9 9
10 -public class CatchMatchLogger { 10 +public class SearchCacheMatchLogger {
11 11
12 private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST"); 12 private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
13 13
14 - public static void doCatchMatchLog(String url, Map<String, String> paramMap) { 14 + public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) {
15 CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap)); 15 CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap));
16 } 16 }
17 17
  18 + public static void doSearchCacheMatchLog(String method, String key) {
  19 + CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key);
  20 + }
  21 +
18 } 22 }
@@ -21,7 +21,7 @@ import com.yoho.search.base.utils.ISearchConstants; @@ -21,7 +21,7 @@ import com.yoho.search.base.utils.ISearchConstants;
21 import com.yoho.search.core.es.agg.IAggregation; 21 import com.yoho.search.core.es.agg.IAggregation;
22 import com.yoho.search.core.es.model.SearchParam; 22 import com.yoho.search.core.es.model.SearchParam;
23 import com.yoho.search.service.aggregations.impls.AggregationFactoryService; 23 import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
24 -import com.yoho.search.service.cache.CatchMatchLogger; 24 +import com.yoho.search.service.cache.SearchCacheMatchLogger;
25 import com.yoho.search.service.cache.SearchCacheFactory; 25 import com.yoho.search.service.cache.SearchCacheFactory;
26 import com.yoho.search.service.cache.model.SearchCache; 26 import com.yoho.search.service.cache.model.SearchCache;
27 import com.yoho.search.service.service.AggregationService; 27 import com.yoho.search.service.service.AggregationService;
@@ -91,7 +91,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService { @@ -91,7 +91,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
91 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 91 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
92 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam); 92 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam);
93 if (cacheJSONArray != null) { 93 if (cacheJSONArray != null) {
94 - CatchMatchLogger.doCatchMatchLog("/productindex/aggRecommendBrand.json", paramMap); 94 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggRecommendBrand.json", paramMap);
95 return new SearchApiResult().setData(cacheJSONArray); 95 return new SearchApiResult().setData(cacheJSONArray);
96 } 96 }
97 // 6、从ES中获取 97 // 6、从ES中获取
@@ -133,7 +133,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService { @@ -133,7 +133,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
133 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 133 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
134 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam); 134 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam);
135 if (cacheJSONArray != null) { 135 if (cacheJSONArray != null) {
136 - CatchMatchLogger.doCatchMatchLog("/productindex/aggRecommendShop.json", paramMap); 136 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggRecommendShop.json", paramMap);
137 return this.getRecommendShopSearchApiResult(cacheJSONArray, page, count); 137 return this.getRecommendShopSearchApiResult(cacheJSONArray, page, count);
138 } 138 }
139 // 6、从ES中获取 139 // 6、从ES中获取
@@ -47,7 +47,7 @@ import com.yoho.search.core.es.model.SearchParam; @@ -47,7 +47,7 @@ import com.yoho.search.core.es.model.SearchParam;
47 import com.yoho.search.core.es.model.SearchResult; 47 import com.yoho.search.core.es.model.SearchResult;
48 import com.yoho.search.core.es.utils.IgnoreSomeException; 48 import com.yoho.search.core.es.utils.IgnoreSomeException;
49 import com.yoho.search.service.aggregations.impls.AggregationFactoryService; 49 import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
50 -import com.yoho.search.service.cache.CatchMatchLogger; 50 +import com.yoho.search.service.cache.SearchCacheMatchLogger;
51 import com.yoho.search.service.cache.SearchCacheFactory; 51 import com.yoho.search.service.cache.SearchCacheFactory;
52 import com.yoho.search.service.cache.model.SearchCache; 52 import com.yoho.search.service.cache.model.SearchCache;
53 import com.yoho.search.service.service.AggregationService; 53 import com.yoho.search.service.service.AggregationService;
@@ -127,7 +127,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -127,7 +127,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
127 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 127 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
128 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, indexName, searchParam); 128 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, indexName, searchParam);
129 if (cacheJSONArray != null) { 129 if (cacheJSONArray != null) {
130 - CatchMatchLogger.doCatchMatchLog("/productindex/aggBrand.json", paramMap); 130 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggBrand.json", paramMap);
131 return new SearchApiResult().setData(cacheJSONArray); 131 return new SearchApiResult().setData(cacheJSONArray);
132 } 132 }
133 // 4、从ES中获取 133 // 4、从ES中获取
@@ -164,7 +164,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -164,7 +164,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
164 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 164 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
165 JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, indexName, searchParam); 165 JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, indexName, searchParam);
166 if (cacheObject != null) { 166 if (cacheObject != null) {
167 - CatchMatchLogger.doCatchMatchLog("/productindex/brands.json", paramMap); 167 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/brands.json", paramMap);
168 return new SearchApiResult().setData(cacheObject); 168 return new SearchApiResult().setData(cacheObject);
169 } 169 }
170 // 4、查询ES 170 // 4、查询ES
@@ -248,7 +248,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -248,7 +248,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
248 final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND; 248 final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
249 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, brandIndexName, searchParam); 249 JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, brandIndexName, searchParam);
250 if (cacheJSONArray != null) { 250 if (cacheJSONArray != null) {
251 - CatchMatchLogger.doCatchMatchLog("/brand/list.json", paramMap); 251 + SearchCacheMatchLogger.doCatchMatchLog("/brand/list.json", paramMap);
252 return new SearchApiResult().setData(cacheJSONArray); 252 return new SearchApiResult().setData(cacheJSONArray);
253 } 253 }
254 // 3、执行搜索 254 // 3、执行搜索
@@ -299,7 +299,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -299,7 +299,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
299 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 299 final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
300 JSONObject groupBrandResult = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, productIndexName, searchParam); 300 JSONObject groupBrandResult = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, productIndexName, searchParam);
301 if (groupBrandResult != null) { 301 if (groupBrandResult != null) {
302 - CatchMatchLogger.doCatchMatchLog("/productindex/groupBrands.json", paramMap); 302 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/groupBrands.json", paramMap);
303 return new SearchApiResult().setData(groupBrandResult); 303 return new SearchApiResult().setData(groupBrandResult);
304 } 304 }
305 // 6、从ES中获取 305 // 6、从ES中获取
@@ -367,7 +367,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -367,7 +367,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
367 // 6、先从缓存中获取,如果能取到,则直接返回 367 // 6、先从缓存中获取,如果能取到,则直接返回
368 JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); 368 JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
369 if (jsonArray != null) { 369 if (jsonArray != null) {
370 - CatchMatchLogger.doCatchMatchLog("/new-shelve.json", paramMap); 370 + SearchCacheMatchLogger.doCatchMatchLog("/new-shelve.json", paramMap);
371 return searchApiResult.setData(jsonArray); 371 return searchApiResult.setData(jsonArray);
372 } 372 }
373 373
@@ -460,7 +460,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe @@ -460,7 +460,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
460 // 7、先从缓存中获取,如果能取到,则直接返回 460 // 7、先从缓存中获取,如果能取到,则直接返回
461 JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); 461 JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
462 if (jsonArray != null) { 462 if (jsonArray != null) {
463 - CatchMatchLogger.doCatchMatchLog("/new_product.json", paramMap); 463 + SearchCacheMatchLogger.doCatchMatchLog("/new_product.json", paramMap);
464 return searchApiResult.setData(jsonArray); 464 return searchApiResult.setData(jsonArray);
465 } 465 }
466 466
@@ -21,7 +21,7 @@ import com.alibaba.fastjson.JSONObject; @@ -21,7 +21,7 @@ import com.alibaba.fastjson.JSONObject;
21 import com.yoho.search.base.utils.ISearchConstants; 21 import com.yoho.search.base.utils.ISearchConstants;
22 import com.yoho.search.core.es.model.SearchParam; 22 import com.yoho.search.core.es.model.SearchParam;
23 import com.yoho.search.core.es.model.SearchResult; 23 import com.yoho.search.core.es.model.SearchResult;
24 -import com.yoho.search.service.cache.CatchMatchLogger; 24 +import com.yoho.search.service.cache.SearchCacheMatchLogger;
25 import com.yoho.search.service.cache.SearchCacheFactory; 25 import com.yoho.search.service.cache.SearchCacheFactory;
26 import com.yoho.search.service.cache.model.SearchCache; 26 import com.yoho.search.service.cache.model.SearchCache;
27 import com.yoho.search.service.service.SearchCacheService; 27 import com.yoho.search.service.service.SearchCacheService;
@@ -96,7 +96,7 @@ public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyS @@ -96,7 +96,7 @@ public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyS
96 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 96 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
97 JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam); 97 JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam);
98 if (cacheObject != null) { 98 if (cacheObject != null) {
99 - CatchMatchLogger.doCatchMatchLog("/productindex/productListWithSupply.json", paramMap); 99 + SearchCacheMatchLogger.doCatchMatchLog("/productindex/productListWithSupply.json", paramMap);
100 return new SearchApiResult().setData(cacheObject); 100 return new SearchApiResult().setData(cacheObject);
101 } 101 }
102 102
@@ -21,7 +21,7 @@ import com.yoho.search.core.es.model.SearchParam; @@ -21,7 +21,7 @@ import com.yoho.search.core.es.model.SearchParam;
21 import com.yoho.search.core.es.model.SearchResult; 21 import com.yoho.search.core.es.model.SearchResult;
22 import com.yoho.search.core.es.utils.IgnoreSomeException; 22 import com.yoho.search.core.es.utils.IgnoreSomeException;
23 import com.yoho.search.service.aggregations.impls.AggregationFactoryService; 23 import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
24 -import com.yoho.search.service.cache.CatchMatchLogger; 24 +import com.yoho.search.service.cache.SearchCacheMatchLogger;
25 import com.yoho.search.service.cache.SearchCacheFactory; 25 import com.yoho.search.service.cache.SearchCacheFactory;
26 import com.yoho.search.service.cache.model.SearchCache; 26 import com.yoho.search.service.cache.model.SearchCache;
27 import com.yoho.search.service.service.SearchCacheService; 27 import com.yoho.search.service.service.SearchCacheService;
@@ -84,7 +84,7 @@ public class RecentServiceImpl implements IRecentService, ApplicationEventPublis @@ -84,7 +84,7 @@ public class RecentServiceImpl implements IRecentService, ApplicationEventPublis
84 if (cacheObject != null) { 84 if (cacheObject != null) {
85 Object result = searchAfterCacheService.dealRecentCacheObject(cacheObject); 85 Object result = searchAfterCacheService.dealRecentCacheObject(cacheObject);
86 searchApiResult.setData(result); 86 searchApiResult.setData(result);
87 - CatchMatchLogger.doCatchMatchLog("/recent.json", paramMap); 87 + SearchCacheMatchLogger.doCatchMatchLog("/recent.json", paramMap);
88 return searchApiResult; 88 return searchApiResult;
89 } 89 }
90 90
@@ -36,6 +36,7 @@ import com.yoho.search.base.utils.RedisKeys; @@ -36,6 +36,7 @@ import com.yoho.search.base.utils.RedisKeys;
36 import com.yoho.search.core.es.model.SearchParam; 36 import com.yoho.search.core.es.model.SearchParam;
37 import com.yoho.search.core.es.model.SearchResult; 37 import com.yoho.search.core.es.model.SearchResult;
38 import com.yoho.search.service.cache.SearchCacheFactory; 38 import com.yoho.search.service.cache.SearchCacheFactory;
  39 +import com.yoho.search.service.cache.SearchCacheMatchLogger;
39 import com.yoho.search.service.cache.model.SearchCache; 40 import com.yoho.search.service.cache.model.SearchCache;
40 import com.yoho.search.service.service.SearchCacheService; 41 import com.yoho.search.service.service.SearchCacheService;
41 import com.yoho.search.service.service.SearchCommonService; 42 import com.yoho.search.service.service.SearchCommonService;
@@ -55,20 +56,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService { @@ -55,20 +56,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
55 56
56 private static final Logger logger = LoggerFactory.getLogger(SearchRecommendServiceImpl.class); 57 private static final Logger logger = LoggerFactory.getLogger(SearchRecommendServiceImpl.class);
57 58
58 - private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");  
59 -  
60 - // 返回智能搜索词的数量  
61 - private static final int SMART_SUGGESTION_TERM_COUNT = 3;  
62 -  
63 - // 返回智能搜索词限制关联商品数量限制  
64 - private static final int SMART_SUGGESTION_COUNT_LIMIT = 20;  
65 - 59 + private static final int SMART_SUGGESTION_TERM_COUNT = 3;// 返回智能搜索词的数量
  60 + private static final int SMART_SUGGESTION_COUNT_LIMIT = 20;// 返回智能搜索词限制关联商品数量限制
66 private static final List<String> DEFAULT_SUGGEST_TIPS = Arrays.asList("潮流", "时尚", "休闲"); 61 private static final List<String> DEFAULT_SUGGEST_TIPS = Arrays.asList("潮流", "时尚", "休闲");
67 -  
68 - private static final Map<String, String> CUSTOM_SUGGEST_CONVERSIONS = new HashMap<>();  
69 -  
70 private static final int VALID_STATUS = 1; 62 private static final int VALID_STATUS = 1;
71 63
  64 + private Map<String, String> CUSTOM_SUGGEST_CONVERSIONS = new HashMap<>();
  65 +
72 @Autowired 66 @Autowired
73 private ISuggestService suggestService; 67 private ISuggestService suggestService;
74 @Autowired 68 @Autowired
@@ -81,14 +75,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService { @@ -81,14 +75,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
81 private SearchKeyWordService searchKeyWordService; 75 private SearchKeyWordService searchKeyWordService;
82 @Autowired 76 @Autowired
83 private ProductIndexBaseService productIndexBaseService; 77 private ProductIndexBaseService productIndexBaseService;
84 -  
85 @Autowired 78 @Autowired
86 private SearchCacheFactory searchCacheFactory; 79 private SearchCacheFactory searchCacheFactory;
87 80
88 private SearchCache recommendSearchCache; 81 private SearchCache recommendSearchCache;
89 82
90 @PostConstruct 83 @PostConstruct
91 - void init() { 84 + private void init() {
92 // it是一个停用词 所以直接配置转换关系 85 // it是一个停用词 所以直接配置转换关系
93 CUSTOM_SUGGEST_CONVERSIONS.put("it", ":CHOCOOLATE,izzue,5cm"); 86 CUSTOM_SUGGEST_CONVERSIONS.put("it", ":CHOCOOLATE,izzue,5cm");
94 // 使用推荐的缓存 87 // 使用推荐的缓存
@@ -288,10 +281,9 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService { @@ -288,10 +281,9 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
288 final String indexName = ISearchConstants.INDEX_NAME_SUGGEST; 281 final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
289 JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam); 282 JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam);
290 if (suggestResult != null) { 283 if (suggestResult != null) {
291 - CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by suggest, keyword = {}.", keywordsToSearch); 284 + SearchCacheMatchLogger.doSearchCacheMatchLog("recommendBySuggestIndex", paramMap);
292 return suggestResult; 285 return suggestResult;
293 } 286 }
294 -  
295 // 5) 调用ES执行搜索 287 // 5) 调用ES执行搜索
296 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, searchParam); 288 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, searchParam);
297 if (searchResult == null) { 289 if (searchResult == null) {
@@ -420,7 +412,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService { @@ -420,7 +412,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
420 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; 412 final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
421 JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, productIndexSearchParam); 413 JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, productIndexSearchParam);
422 if (jsonObject != null) { 414 if (jsonObject != null) {
423 - CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by skns, sknList = {}.", sknList); 415 + SearchCacheMatchLogger.doSearchCacheMatchLog("aggKeywordsBySkns", queryWord);
424 return jsonObject.getString("aggKeyword"); 416 return jsonObject.getString("aggKeyword");
425 } 417 }
426 418
@@ -477,7 +469,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService { @@ -477,7 +469,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
477 final String indexName = ISearchConstants.INDEX_NAME_CONVERSION; 469 final String indexName = ISearchConstants.INDEX_NAME_CONVERSION;
478 JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam); 470 JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam);
479 if (suggestResult != null) { 471 if (suggestResult != null) {
480 - CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by conversion, keyword = {}.", queryWord); 472 + SearchCacheMatchLogger.doSearchCacheMatchLog("getSuggestConversionDestBySource", queryWord);
481 return suggestResult.getString("dest"); 473 return suggestResult.getString("dest");
482 } 474 }
483 475