Authored by 胡古飞

fix SearchRecommendServiceImpl

... ... @@ -7,12 +7,16 @@ import org.slf4j.LoggerFactory;
import com.yoho.search.base.utils.HttpServletRequestUtils;
public class CatchMatchLogger {
public class SearchCacheMatchLogger {
private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
public static void doCatchMatchLog(String url, Map<String, String> paramMap) {
public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) {
CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap));
}
public static void doSearchCacheMatchLog(String method, String key) {
CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key);
}
}
... ...
... ... @@ -21,7 +21,7 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.cache.CatchMatchLogger;
import com.yoho.search.service.cache.SearchCacheMatchLogger;
import com.yoho.search.service.cache.SearchCacheFactory;
import com.yoho.search.service.cache.model.SearchCache;
import com.yoho.search.service.service.AggregationService;
... ... @@ -91,7 +91,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam);
if (cacheJSONArray != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/aggRecommendBrand.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggRecommendBrand.json", paramMap);
return new SearchApiResult().setData(cacheJSONArray);
}
// 6、从ES中获取
... ... @@ -133,7 +133,7 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, productIndexName, searchParam);
if (cacheJSONArray != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/aggRecommendShop.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggRecommendShop.json", paramMap);
return this.getRecommendShopSearchApiResult(cacheJSONArray, page, count);
}
// 6、从ES中获取
... ...
... ... @@ -47,7 +47,7 @@ import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.cache.CatchMatchLogger;
import com.yoho.search.service.cache.SearchCacheMatchLogger;
import com.yoho.search.service.cache.SearchCacheFactory;
import com.yoho.search.service.cache.model.SearchCache;
import com.yoho.search.service.service.AggregationService;
... ... @@ -127,7 +127,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, indexName, searchParam);
if (cacheJSONArray != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/aggBrand.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/aggBrand.json", paramMap);
return new SearchApiResult().setData(cacheJSONArray);
}
// 4、从ES中获取
... ... @@ -164,7 +164,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, indexName, searchParam);
if (cacheObject != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/brands.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/brands.json", paramMap);
return new SearchApiResult().setData(cacheObject);
}
// 4、查询ES
... ... @@ -248,7 +248,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, brandIndexName, searchParam);
if (cacheJSONArray != null) {
CatchMatchLogger.doCatchMatchLog("/brand/list.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/brand/list.json", paramMap);
return new SearchApiResult().setData(cacheJSONArray);
}
// 3、执行搜索
... ... @@ -299,7 +299,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject groupBrandResult = searchCacheService.getJSONObjectFromCache(brandAndShopSearchCache, productIndexName, searchParam);
if (groupBrandResult != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/groupBrands.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/groupBrands.json", paramMap);
return new SearchApiResult().setData(groupBrandResult);
}
// 6、从ES中获取
... ... @@ -367,7 +367,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
// 6、先从缓存中获取,如果能取到,则直接返回
JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (jsonArray != null) {
CatchMatchLogger.doCatchMatchLog("/new-shelve.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/new-shelve.json", paramMap);
return searchApiResult.setData(jsonArray);
}
... ... @@ -460,7 +460,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
// 7、先从缓存中获取,如果能取到,则直接返回
JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(brandAndShopSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (jsonArray != null) {
CatchMatchLogger.doCatchMatchLog("/new_product.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/new_product.json", paramMap);
return searchApiResult.setData(jsonArray);
}
... ...
... ... @@ -21,7 +21,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.cache.CatchMatchLogger;
import com.yoho.search.service.cache.SearchCacheMatchLogger;
import com.yoho.search.service.cache.SearchCacheFactory;
import com.yoho.search.service.cache.model.SearchCache;
import com.yoho.search.service.service.SearchCacheService;
... ... @@ -96,7 +96,7 @@ public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyS
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam);
if (cacheObject != null) {
CatchMatchLogger.doCatchMatchLog("/productindex/productListWithSupply.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/productindex/productListWithSupply.json", paramMap);
return new SearchApiResult().setData(cacheObject);
}
... ...
... ... @@ -21,7 +21,7 @@ import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.cache.CatchMatchLogger;
import com.yoho.search.service.cache.SearchCacheMatchLogger;
import com.yoho.search.service.cache.SearchCacheFactory;
import com.yoho.search.service.cache.model.SearchCache;
import com.yoho.search.service.service.SearchCacheService;
... ... @@ -84,7 +84,7 @@ public class RecentServiceImpl implements IRecentService, ApplicationEventPublis
if (cacheObject != null) {
Object result = searchAfterCacheService.dealRecentCacheObject(cacheObject);
searchApiResult.setData(result);
CatchMatchLogger.doCatchMatchLog("/recent.json", paramMap);
SearchCacheMatchLogger.doCatchMatchLog("/recent.json", paramMap);
return searchApiResult;
}
... ...
... ... @@ -36,6 +36,7 @@ import com.yoho.search.base.utils.RedisKeys;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.cache.SearchCacheFactory;
import com.yoho.search.service.cache.SearchCacheMatchLogger;
import com.yoho.search.service.cache.model.SearchCache;
import com.yoho.search.service.service.SearchCacheService;
import com.yoho.search.service.service.SearchCommonService;
... ... @@ -55,20 +56,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
private static final Logger logger = LoggerFactory.getLogger(SearchRecommendServiceImpl.class);
private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
// 返回智能搜索词的数量
private static final int SMART_SUGGESTION_TERM_COUNT = 3;
// 返回智能搜索词限制关联商品数量限制
private static final int SMART_SUGGESTION_COUNT_LIMIT = 20;
private static final int SMART_SUGGESTION_TERM_COUNT = 3;// 返回智能搜索词的数量
private static final int SMART_SUGGESTION_COUNT_LIMIT = 20;// 返回智能搜索词限制关联商品数量限制
private static final List<String> DEFAULT_SUGGEST_TIPS = Arrays.asList("潮流", "时尚", "休闲");
private static final Map<String, String> CUSTOM_SUGGEST_CONVERSIONS = new HashMap<>();
private static final int VALID_STATUS = 1;
private Map<String, String> CUSTOM_SUGGEST_CONVERSIONS = new HashMap<>();
@Autowired
private ISuggestService suggestService;
@Autowired
... ... @@ -81,14 +75,13 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
private SearchKeyWordService searchKeyWordService;
@Autowired
private ProductIndexBaseService productIndexBaseService;
@Autowired
private SearchCacheFactory searchCacheFactory;
private SearchCache recommendSearchCache;
@PostConstruct
void init() {
private void init() {
// it是一个停用词 所以直接配置转换关系
CUSTOM_SUGGEST_CONVERSIONS.put("it", ":CHOCOOLATE,izzue,5cm");
// 使用推荐的缓存
... ... @@ -288,10 +281,9 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam);
if (suggestResult != null) {
CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by suggest, keyword = {}.", keywordsToSearch);
SearchCacheMatchLogger.doSearchCacheMatchLog("recommendBySuggestIndex", paramMap);
return suggestResult;
}
// 5) 调用ES执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, searchParam);
if (searchResult == null) {
... ... @@ -420,7 +412,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, productIndexSearchParam);
if (jsonObject != null) {
CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by skns, sknList = {}.", sknList);
SearchCacheMatchLogger.doSearchCacheMatchLog("aggKeywordsBySkns", queryWord);
return jsonObject.getString("aggKeyword");
}
... ... @@ -477,7 +469,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
final String indexName = ISearchConstants.INDEX_NAME_CONVERSION;
JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(recommendSearchCache, indexName, searchParam);
if (suggestResult != null) {
CACHE_MATCH_REQUEST.info("match cache for product list search recommendation by conversion, keyword = {}.", queryWord);
SearchCacheMatchLogger.doSearchCacheMatchLog("getSuggestConversionDestBySource", queryWord);
return suggestResult.getString("dest");
}
... ...