Authored by Gino Zhang

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

@@ -127,4 +127,11 @@ public class AggregationFactoryService { @@ -127,4 +127,11 @@ public class AggregationFactoryService {
127 return new SortGroupAggregation(paramMap); 127 return new SortGroupAggregation(paramMap);
128 } 128 }
129 129
  130 + public IAggregation getKeywordAggregation(int aggCount) {
  131 + return new KeywordAggregation(aggCount);
  132 + }
  133 +
  134 + public IAggregation getShopAggregation(int aggCount) {
  135 + return new ShopAggregation(aggCount);
  136 + }
130 } 137 }
  1 +package com.yoho.search.service.aggregations.impls;
  2 +
  3 +public class KeywordAggregation extends AbstractSingleFieldAggregation {
  4 +
  5 + public KeywordAggregation(int count) {
  6 + super(count);
  7 + }
  8 +
  9 + @Override
  10 + public String aggName() {
  11 + return "keywordAgg";
  12 + }
  13 +
  14 + @Override
  15 + protected String getField() {
  16 + return "productAttrField";
  17 + }
  18 +}
  1 +package com.yoho.search.service.aggregations.impls;
  2 +
  3 +public class ShopAggregation extends AbstractSingleFieldAggregation {
  4 +
  5 + public ShopAggregation(int count) {
  6 + super(count);
  7 + }
  8 +
  9 + @Override
  10 + public String aggName() {
  11 + return "shopIdAgg";
  12 + }
  13 +
  14 + @Override
  15 + protected String getField() {
  16 + return "shopId";
  17 + }
  18 +}
@@ -175,4 +175,32 @@ public class ProductIndexController implements ApplicationEventPublisherAware { @@ -175,4 +175,32 @@ public class ProductIndexController implements ApplicationEventPublisherAware {
175 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); 175 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
176 return productIndexService.aggSpecialoffer(paramMap); 176 return productIndexService.aggSpecialoffer(paramMap);
177 } 177 }
  178 +
  179 + /**
  180 + * 从商品列表聚合关键词,随机返回关键词
  181 + *
  182 + * @param request
  183 + * @return
  184 + */
  185 + @DownGradeAble(key = "recommendKeyword")
  186 + @RequestMapping(method = RequestMethod.GET, value = "/recommendKeyword")
  187 + @ResponseBody
  188 + public SearchApiResult recommendKeyword(HttpServletRequest request) {
  189 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  190 + return productIndexService.aggKeywords(paramMap);
  191 + }
  192 +
  193 + /**
  194 + * 聚合关键词
  195 + *
  196 + * @param request
  197 + * @return
  198 + */
  199 + @DownGradeAble(key = "recommendShop")
  200 + @RequestMapping(method = RequestMethod.GET, value = "/recommendShop")
  201 + @ResponseBody
  202 + public SearchApiResult recommendShop(HttpServletRequest request) {
  203 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  204 + return productIndexService.aggShops(paramMap);
  205 + }
178 } 206 }
1 package com.yoho.search.service.service; 1 package com.yoho.search.service.service;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.Arrays;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 - 3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.error.event.SearchEvent;
  5 +import com.yoho.search.base.utils.EventReportEnum;
  6 +import com.yoho.search.base.utils.ISearchConstants;
  7 +import com.yoho.search.core.es.agg.IAggregation;
  8 +import com.yoho.search.core.es.model.SearchParam;
  9 +import com.yoho.search.core.es.model.SearchResult;
  10 +import com.yoho.search.core.es.utils.IgnoreSomeException;
  11 +import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
  12 +import com.yoho.search.service.service.helper.SearchServiceHelper;
  13 +import com.yoho.search.service.utils.SearchRequestParams;
8 import org.apache.commons.lang.StringUtils; 14 import org.apache.commons.lang.StringUtils;
9 import org.elasticsearch.index.query.BoolQueryBuilder; 15 import org.elasticsearch.index.query.BoolQueryBuilder;
10 import org.elasticsearch.index.query.QueryBuilder; 16 import org.elasticsearch.index.query.QueryBuilder;
@@ -17,17 +23,10 @@ import org.springframework.context.ApplicationEventPublisher; @@ -17,17 +23,10 @@ import org.springframework.context.ApplicationEventPublisher;
17 import org.springframework.context.ApplicationEventPublisherAware; 23 import org.springframework.context.ApplicationEventPublisherAware;
18 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
19 25
20 -import com.alibaba.fastjson.JSONObject;  
21 -import com.yoho.error.event.SearchEvent;  
22 -import com.yoho.search.base.utils.EventReportEnum;  
23 -import com.yoho.search.base.utils.ISearchConstants;  
24 -import com.yoho.search.core.es.agg.IAggregation;  
25 -import com.yoho.search.core.es.model.SearchParam;  
26 -import com.yoho.search.core.es.model.SearchResult;  
27 -import com.yoho.search.core.es.utils.IgnoreSomeException;  
28 -import com.yoho.search.service.aggregations.impls.AggregationFactoryService;  
29 -import com.yoho.search.service.service.helper.SearchServiceHelper;  
30 -import com.yoho.search.service.utils.SearchRequestParams; 26 +import java.util.ArrayList;
  27 +import java.util.Arrays;
  28 +import java.util.List;
  29 +import java.util.Map;
31 30
32 @Service 31 @Service
33 public class AggregationService implements ApplicationEventPublisherAware { 32 public class AggregationService implements ApplicationEventPublisherAware {
@@ -324,4 +323,29 @@ public class AggregationService implements ApplicationEventPublisherAware { @@ -324,4 +323,29 @@ public class AggregationService implements ApplicationEventPublisherAware {
324 return this.getAggNameAndResponse(isSecialofferAggregation, searchParam, paramMap, filterParamName); 323 return this.getAggNameAndResponse(isSecialofferAggregation, searchParam, paramMap, filterParamName);
325 } 324 }
326 325
  326 + /**
  327 + * 获取商品关键词的聚合,来源与风格、款式和属性。
  328 + *
  329 + * @param searchParam
  330 + * @param paramMap
  331 + * @return
  332 + * @throws Exception
  333 + */
  334 + public JSONObject getKeywordAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
  335 + IAggregation keywordAggregation = aggregationFactoryService.getKeywordAggregation(aggCount);
  336 + return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
  337 + }
  338 +
  339 + /**
  340 + * 获取商品关键词的聚合,来源与风格、款式和属性。
  341 + *
  342 + * @param searchParam
  343 + * @param paramMap
  344 + * @return
  345 + * @throws Exception
  346 + */
  347 + public JSONObject getShopAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
  348 + IAggregation keywordAggregation = aggregationFactoryService.getShopAggregation(aggCount);
  349 + return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
  350 + }
327 } 351 }
1 package com.yoho.search.service.servicenew; 1 package com.yoho.search.service.servicenew;
2 2
3 -import java.util.Map;  
4 -  
5 import com.yoho.search.service.vo.SearchApiResult; 3 import com.yoho.search.service.vo.SearchApiResult;
6 4
  5 +import java.util.Map;
  6 +
7 public interface IProductIndexService { 7 public interface IProductIndexService {
8 8
9 /** 9 /**
@@ -83,4 +83,13 @@ public interface IProductIndexService { @@ -83,4 +83,13 @@ public interface IProductIndexService {
83 * @return 83 * @return
84 */ 84 */
85 public SearchApiResult aggSpecialoffer(Map<String, String> paramMap); 85 public SearchApiResult aggSpecialoffer(Map<String, String> paramMap);
  86 +
  87 + /**
  88 + * 商品关键词的聚合,来源与风格、款式和属性。
  89 + * @param paramMap
  90 + * @return
  91 + */
  92 + SearchApiResult aggKeywords(Map<String, String> paramMap);
  93 +
  94 + SearchApiResult aggShops(Map<String, String> paramMap);
86 } 95 }
1 package com.yoho.search.service.servicenew.impl; 1 package com.yoho.search.service.servicenew.impl;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -import java.util.Map;  
6 - 3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.error.event.SearchEvent;
7 import com.yoho.search.base.utils.EventReportEnum; 5 import com.yoho.search.base.utils.EventReportEnum;
8 import com.yoho.search.base.utils.JsonUtil; 6 import com.yoho.search.base.utils.JsonUtil;
  7 +import com.yoho.search.core.es.model.SearchParam;
  8 +import com.yoho.search.core.es.utils.IgnoreSomeException;
9 import com.yoho.search.service.service.AggregationService; 9 import com.yoho.search.service.service.AggregationService;
10 import com.yoho.search.service.service.SearchCommonService; 10 import com.yoho.search.service.service.SearchCommonService;
11 import com.yoho.search.service.service.helper.SearchServiceHelper; 11 import com.yoho.search.service.service.helper.SearchServiceHelper;
12 import com.yoho.search.service.servicenew.IProductIndexService; 12 import com.yoho.search.service.servicenew.IProductIndexService;
13 -import com.yoho.search.core.es.utils.IgnoreSomeException;  
14 import com.yoho.search.service.vo.SearchApiResult; 13 import com.yoho.search.service.vo.SearchApiResult;
15 -  
16 import org.apache.commons.lang.StringUtils; 14 import org.apache.commons.lang.StringUtils;
17 import org.slf4j.Logger; 15 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 16 import org.slf4j.LoggerFactory;
@@ -21,9 +19,9 @@ import org.springframework.context.ApplicationEventPublisher; @@ -21,9 +19,9 @@ import org.springframework.context.ApplicationEventPublisher;
21 import org.springframework.context.ApplicationEventPublisherAware; 19 import org.springframework.context.ApplicationEventPublisherAware;
22 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
23 21
24 -import com.alibaba.fastjson.JSONObject;  
25 -import com.yoho.error.event.SearchEvent;  
26 -import com.yoho.search.core.es.model.SearchParam; 22 +import java.util.ArrayList;
  23 +import java.util.List;
  24 +import java.util.Map;
27 25
28 @Service 26 @Service
29 public class ProductIndexServiceImpl implements IProductIndexService,ApplicationEventPublisherAware { 27 public class ProductIndexServiceImpl implements IProductIndexService,ApplicationEventPublisherAware {
@@ -245,4 +243,30 @@ public class ProductIndexServiceImpl implements IProductIndexService,Application @@ -245,4 +243,30 @@ public class ProductIndexServiceImpl implements IProductIndexService,Application
245 } 243 }
246 }); 244 });
247 } 245 }
  246 +
  247 + @Override
  248 + public SearchApiResult aggKeywords(Map<String, String> paramMap) {
  249 + return this.getSearchApiResult("aggKeywords", paramMap, new Searcher() {
  250 + @Override
  251 + public Object getResult() throws Exception {
  252 + SearchParam searchParam = getSearchParamFromMap(paramMap);
  253 + JSONObject jsonObject = aggregationService.getKeywordAggregationResult(searchParam, paramMap, 50);
  254 + Object keywordAgg = jsonObject.get("keywordAgg");
  255 + return keywordAgg;
  256 + }
  257 + });
  258 + }
  259 +
  260 + @Override
  261 + public SearchApiResult aggShops(Map<String, String> paramMap) {
  262 + return this.getSearchApiResult("aggShops", paramMap, new Searcher() {
  263 + @Override
  264 + public Object getResult() throws Exception {
  265 + SearchParam searchParam = getSearchParamFromMap(paramMap);
  266 + JSONObject jsonObject = aggregationService.getShopAggregationResult(searchParam, paramMap, 50);
  267 + Object shopIdAgg = jsonObject.get("shopIdAgg");
  268 + return shopIdAgg;
  269 + }
  270 + });
  271 + }
248 } 272 }