Authored by wangnan9279

ufo

... ... @@ -19,7 +19,7 @@ import java.util.Map;
* @version 2018/9/14
*/
@Controller
public class UfoProductListController {
public class UfoController {
@Autowired
private UfoProductListService ufoProductListService;
... ... @@ -56,11 +56,11 @@ public class UfoProductListController {
return ufoProductListService.recommendList(paramMap);
}
@RequestMapping(method = RequestMethod.GET, value = "/ufo/suggest")
@RequestMapping(method = RequestMethod.GET, value = "/ufo/suggestList")
@ResponseBody
public SearchApiResult suggest(HttpServletRequest request) {
public SearchApiResult suggestList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return ufoProductListService.suggest(paramMap);
return ufoProductListService.suggestList(paramMap);
}
}
... ...
... ... @@ -2,8 +2,8 @@ package com.yoho.search.service.scene.shopbrand;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.cache.beans.AbstractCacheComponent;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.utils.SearchApiResultUtils;
... ... @@ -30,7 +30,7 @@ import java.util.Map;
* @version 2018/9/17
*/
@Service
public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> {
public class UfoAggBrandService {
private static final Logger logger = LoggerFactory.getLogger(UfoAggBrandService.class);
@Autowired
... ... @@ -40,7 +40,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> {
@Autowired
private SearchCommonService searchCommonService;
@SearchCacheAble(cacheName = "UFO_BRAND_LIST", cacheInMinute = 10)
public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
try {
// 1、构造带filter和query的SearchParam
... ... @@ -57,7 +57,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> {
searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder()));
// 3、调父类方法执行查询
JSONArray brandJSONArray = super.queryWithCache(searchParam, brandAggregation);
JSONArray brandJSONArray = doRealQuery(searchParam, brandAggregation);
JSONObject dataMap = new JSONObject();
dataMap.put("brand_list", brandJSONArray);
return new SearchApiResult().setData(dataMap);
... ... @@ -66,23 +66,12 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> {
}
}
@Override
protected String cacheSceneKey() {
return "AGG_UFO_BRAND_LIST";
}
@Override
protected int cacheTimeInMinute() {
return 0;//CacheTimeConstants.CACHE_30_MINUTE;
}
@Override
protected JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
private JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
// 1、从参数中获取IAggregation brandAggregation
IAggregation brandAggregation = (IAggregation) params[0];
// 2、从ES中获取
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);//this.doSearchForAggregation(searchParam, AggregationServiceIndex);
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
... ...
package com.yoho.search.service.scene.ufo;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.core.es.model.SearchParam;
... ... @@ -39,6 +40,7 @@ public class UfoProductListService {
private static final String RETURN_LIST_NAME = "product_list";
private static final Integer RECOMMEND_LIMIT = 30;
@SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = 10)
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、参数校验
... ... @@ -81,13 +83,14 @@ public class UfoProductListService {
}
}
@SearchCacheAble(cacheName = "UFO_RECOMMEND_LIST", cacheInMinute = 10)
public SearchApiResult recommendList(Map<String, String> paramMap) {
String query = MapUtils.getString(paramMap, "query");
Integer brandId = MapUtils.getInteger(paramMap, "brand");
Integer midSortId = MapUtils.getInteger(paramMap, "midSort");
Integer not_id = MapUtils.getInteger(paramMap, "not_id");
if (StringUtils.isBlank(query) || brandId == null || midSortId == null) {
return new SearchApiResult().setCode(400).setMessage("参数不合法,query,brand,midSort必传");
if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) {
return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
}
//第一次查询
paramMap.put("viewNum", "1000");
... ... @@ -146,7 +149,7 @@ public class UfoProductListService {
}
}
public SearchApiResult suggest(Map<String, String> paramMap) {
public SearchApiResult suggestList(Map<String, String> paramMap) {
try {
// 1、参数校验
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
... ...
... ... @@ -2,8 +2,8 @@ package com.yoho.search.service.scene.ufo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.cache.beans.AbstractCacheComponent;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
... ... @@ -32,7 +32,7 @@ import java.util.Map;
* @version 2018/9/17
*/
@Service
public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
public class UfoSelectionsService {
private static final Logger logger = LoggerFactory.getLogger(UfoSelectionsService.class);
... ... @@ -43,15 +43,9 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
@Autowired
private SearchCommonService searchCommonService;
@SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = 10)
public SearchApiResult getSelectionsForApp(Map<String, String> paramMap) {
try {
return this.getSelectionsForApp(paramMap, null);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
}
}
public SearchApiResult getSelectionsForApp(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
// 1)构造searchParam
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap, null);
... ... @@ -60,14 +54,15 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
searchParam.setQuery(queryBuilder);
searchParam.setSize(0);
// 2)调父类查询
JSONObject result = super.queryWithCache(searchParam, paramMap);
JSONObject result = doRealQuery(searchParam, paramMap);
// 3)生成结果
return new SearchApiResult().setData(result);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
}
}
@Override
protected JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
private JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
Map<String, String> paramMap = (Map<String, String>) params[0];
// 构造聚合报文
... ... @@ -89,42 +84,26 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
return dataMap;
}
@Override
protected int cacheTimeInMinute() {
return 0;
}
@Override
protected String cacheSceneKey() {
return "UFO_SELECTIONS_FOR_APP";
}
/**
* 构造不带提前聚合逻辑的报文
**/
private List<AbstractAggregationBuilder<?>> getAllAggregationBuilders(Map<String, String> paramMap) {
List<AbstractAggregationBuilder<?>> list = new ArrayList<AbstractAggregationBuilder<?>>();
// 6)品牌
//品牌
list.add(aggregationFactory.getUfoBrandAggregation(paramMap).getBuilder());
//品类
list.add(aggregationFactory.getUfoSortAggregation(paramMap).getBuilder());
// 2)性别
//性别
list.add(aggregationFactory.getUfoGenderAggregation().getBuilder());
// 8)尺码
//尺码
list.add(aggregationFactory.getUfoSizeAggregation().getBuilder());
return list;
}
private Map<String, Object> getAggResultMap(Map<String, String> paramMap, Map<String, Aggregation> aggMaps) {
Map<String, Object> filter = new HashMap<String, Object>();
// 2)获取性别的聚合结果
// 性别的聚合结果
IAggregation genderAggregation = aggregationFactory.getUfoGenderAggregation();
Object genderResponse = genderAggregation.getAggregationResponseMap(aggMaps);
if (genderResponse != null) {
... ... @@ -133,7 +112,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
filter.put("gender", new JSONArray());
}
// 6)获取品牌层面的聚合结果
// 6品牌层面的聚合结果
IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap);
Object brandResponse = brandAggregation.getAggregationResponseMap(aggMaps);
if (brandResponse != null) {
... ... @@ -151,7 +130,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
filter.put("sort", new JSONArray());
}
// 7)获取尺码聚合结果[尺码不会提前聚合]
// 尺码
IAggregation sizeAggregation = aggregationFactory.getUfoSizeAggregation();
Object sizeResponse = sizeAggregation.getAggregationResponseMap(aggMaps);
if (sizeResponse != null) {
... ... @@ -160,7 +139,6 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
filter.put("size", new JSONArray());
}
return filter;
}
... ...