...
|
...
|
@@ -18,13 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.common.cache.model.SearchCache;
|
|
|
import com.yoho.search.common.cache.aop.SearchCacheAble;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.base.SearchDynamicConfigService;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import com.yoho.search.service.base.index.ProductIndexBaseService;
|
|
|
import com.yoho.search.service.scene.common.AbstractCacheAbleService;
|
|
|
|
|
|
/**
|
|
|
* 店铺外找相似
|
...
|
...
|
@@ -33,7 +32,7 @@ import com.yoho.search.service.scene.common.AbstractCacheAbleService; |
|
|
*
|
|
|
*/
|
|
|
@Service
|
|
|
public class SearchLikeNotInShopService extends AbstractCacheAbleService {
|
|
|
public class SearchLikeNotInShopService{
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SearchLikeNotInShopService.class);
|
|
|
|
...
|
...
|
@@ -44,17 +43,13 @@ public class SearchLikeNotInShopService extends AbstractCacheAbleService { |
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
|
|
|
@Override
|
|
|
public SearchCache getSearchCache() {
|
|
|
return searchCacheFactory.getSearchLikeSearchCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 店铺外推荐
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
@SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_NOT_IN_SHOP", includeParams = { "product_skn", "viewNum" })
|
|
|
public SearchApiResult searchLikeNotInShop(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、获取参数
|
...
|
...
|
@@ -65,32 +60,25 @@ public class SearchLikeNotInShopService extends AbstractCacheAbleService { |
|
|
// 2、检测分页参数【默认30条,最多60条】
|
|
|
int pageSize = searchLikeHelper.getPageSize(paramMap);
|
|
|
|
|
|
// 3、从缓存中获取,找到则直接返回
|
|
|
String redisCacheKey = searchCacheKeyHelper.getSearchLikeNotInShopKeyCache(productSkn, pageSize);
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, redisCacheKey);
|
|
|
if (cacheObject != null) {
|
|
|
return new SearchApiResult().setData(cacheObject);
|
|
|
}
|
|
|
|
|
|
// 4、获取当前查询的SKN的基本信息
|
|
|
// 2、获取当前查询的SKN的基本信息
|
|
|
JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);
|
|
|
if (productInfoInEs == null) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("SKN不存在");
|
|
|
}
|
|
|
|
|
|
// 5、设置SearchParams
|
|
|
// 3、设置SearchParams
|
|
|
List<SearchParam> searchParams = new ArrayList<SearchParam>();
|
|
|
int sameSortCount = searchDynamicConfigService.getSearchLikeNotInShopSameSortPercent() * pageSize / 100;
|
|
|
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), sameSortCount, true));
|
|
|
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize - sameSortCount, false));
|
|
|
|
|
|
// 6、获取搜索结果[截取条数]
|
|
|
// 4、获取搜索结果[截取条数]
|
|
|
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
|
|
|
if (tempProductList.size() > pageSize) {
|
|
|
tempProductList = tempProductList.subList(0, pageSize);
|
|
|
}
|
|
|
|
|
|
// 7、构造真实返回结果
|
|
|
// 5、构造真实返回结果
|
|
|
List<Map<String, Object>> productListResults = new ArrayList<Map<String, Object>>();
|
|
|
if (!tempProductList.isEmpty()) {
|
|
|
productListResults = productIndexBaseService.getProductListWithPricePlan(tempProductList);
|
...
|
...
|
@@ -102,17 +90,14 @@ public class SearchLikeNotInShopService extends AbstractCacheAbleService { |
|
|
result.put("total", productListResults.size());
|
|
|
result.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));
|
|
|
result.put("product_list", productListResults);
|
|
|
|
|
|
// 8、结果加入缓存
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, redisCacheKey, result);
|
|
|
return new SearchApiResult().setData(result);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("searchLikeNotInShop Exception").setCode(500);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
|
|
|
// 1、设置SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
...
|
...
|
|