Authored by Gino Zhang

品类页/模糊搜索页增加推荐词和店铺推荐的功能

... ... @@ -127,4 +127,11 @@ public class AggregationFactoryService {
return new SortGroupAggregation(paramMap);
}
public IAggregation getKeywordAggregation(int aggCount) {
return new KeywordAggregation(aggCount);
}
public IAggregation getShopAggregation(int aggCount) {
return new ShopAggregation(aggCount);
}
}
... ...
package com.yoho.search.service.aggregations.impls;
public class KeywordAggregation extends AbstractSingleFieldAggregation {
public KeywordAggregation(int count) {
super(count);
}
@Override
public String aggName() {
return "keywordAgg";
}
@Override
protected String getField() {
return "productAttrField";
}
}
... ...
package com.yoho.search.service.aggregations.impls;
public class ShopAggregation extends AbstractSingleFieldAggregation {
public ShopAggregation(int count) {
super(count);
}
@Override
public String aggName() {
return "shopIdAgg";
}
@Override
protected String getField() {
return "shopId";
}
}
... ...
... ... @@ -175,4 +175,32 @@ public class ProductIndexController implements ApplicationEventPublisherAware {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggSpecialoffer(paramMap);
}
/**
* 从商品列表聚合关键词,随机返回关键词
*
* @param request
* @return
*/
@DownGradeAble(key = "recommendKeyword")
@RequestMapping(method = RequestMethod.GET, value = "/recommendKeyword")
@ResponseBody
public SearchApiResult recommendKeyword(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggKeywords(paramMap);
}
/**
* 聚合关键词
*
* @param request
* @return
*/
@DownGradeAble(key = "recommendShop")
@RequestMapping(method = RequestMethod.GET, value = "/recommendShop")
@ResponseBody
public SearchApiResult recommendShop(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggShops(paramMap);
}
}
... ...
package com.yoho.search.service.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
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.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.service.helper.SearchServiceHelper;
import com.yoho.search.service.utils.SearchRequestParams;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
... ... @@ -17,17 +23,10 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
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.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.service.helper.SearchServiceHelper;
import com.yoho.search.service.utils.SearchRequestParams;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Service
public class AggregationService implements ApplicationEventPublisherAware {
... ... @@ -324,4 +323,29 @@ public class AggregationService implements ApplicationEventPublisherAware {
return this.getAggNameAndResponse(isSecialofferAggregation, searchParam, paramMap, filterParamName);
}
/**
* 获取商品关键词的聚合,来源与风格、款式和属性。
*
* @param searchParam
* @param paramMap
* @return
* @throws Exception
*/
public JSONObject getKeywordAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
IAggregation keywordAggregation = aggregationFactoryService.getKeywordAggregation(aggCount);
return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
}
/**
* 获取商品关键词的聚合,来源与风格、款式和属性。
*
* @param searchParam
* @param paramMap
* @return
* @throws Exception
*/
public JSONObject getShopAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
IAggregation keywordAggregation = aggregationFactoryService.getShopAggregation(aggCount);
return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
}
}
... ...
package com.yoho.search.service.servicenew;
import java.util.Map;
import com.yoho.search.service.vo.SearchApiResult;
import java.util.Map;
public interface IProductIndexService {
/**
... ... @@ -83,4 +83,13 @@ public interface IProductIndexService {
* @return
*/
public SearchApiResult aggSpecialoffer(Map<String, String> paramMap);
/**
* 商品关键词的聚合,来源与风格、款式和属性。
* @param paramMap
* @return
*/
SearchApiResult aggKeywords(Map<String, String> paramMap);
SearchApiResult aggShops(Map<String, String> paramMap);
}
... ...
package com.yoho.search.service.servicenew.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.JsonUtil;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.service.AggregationService;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.servicenew.IProductIndexService;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.vo.SearchApiResult;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -21,9 +19,9 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.core.es.model.SearchParam;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class ProductIndexServiceImpl implements IProductIndexService,ApplicationEventPublisherAware {
... ... @@ -245,4 +243,30 @@ public class ProductIndexServiceImpl implements IProductIndexService,Application
}
});
}
@Override
public SearchApiResult aggKeywords(Map<String, String> paramMap) {
return this.getSearchApiResult("aggKeywords", paramMap, new Searcher() {
@Override
public Object getResult() throws Exception {
SearchParam searchParam = getSearchParamFromMap(paramMap);
JSONObject jsonObject = aggregationService.getKeywordAggregationResult(searchParam, paramMap, 50);
Object keywordAgg = jsonObject.get("keywordAgg");
return keywordAgg;
}
});
}
@Override
public SearchApiResult aggShops(Map<String, String> paramMap) {
return this.getSearchApiResult("aggShops", paramMap, new Searcher() {
@Override
public Object getResult() throws Exception {
SearchParam searchParam = getSearchParamFromMap(paramMap);
JSONObject jsonObject = aggregationService.getShopAggregationResult(searchParam, paramMap, 50);
Object shopIdAgg = jsonObject.get("shopIdAgg");
return shopIdAgg;
}
});
}
}
... ...