Showing
1 changed file
with
27 additions
and
5 deletions
1 | package com.yoho.search.restapi.tools; | 1 | package com.yoho.search.restapi.tools; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | -import com.yoho.search.base.utils.CollectionUtils; | ||
5 | -import com.yoho.search.base.utils.Transfer; | ||
6 | -import com.yoho.search.base.utils.DateUtil; | ||
7 | -import com.yoho.search.base.utils.SearchPageIdDefine; | 4 | +import com.yoho.search.base.utils.*; |
8 | import com.yoho.search.common.utils.HttpServletRequestUtils; | 5 | import com.yoho.search.common.utils.HttpServletRequestUtils; |
9 | import com.yoho.search.common.utils.SearchKeyWordUtils; | 6 | import com.yoho.search.common.utils.SearchKeyWordUtils; |
7 | +import com.yoho.search.core.es.model.SearchParam; | ||
8 | +import com.yoho.search.core.es.model.SearchResult; | ||
10 | import com.yoho.search.models.SearchApiResult; | 9 | import com.yoho.search.models.SearchApiResult; |
11 | import com.yoho.search.recall.beans.builder.UserRecallRequestBuilder; | 10 | import com.yoho.search.recall.beans.builder.UserRecallRequestBuilder; |
12 | import com.yoho.search.recall.beans.cache.SknReturnInfoCacheBean; | 11 | import com.yoho.search.recall.beans.cache.SknReturnInfoCacheBean; |
@@ -15,9 +14,12 @@ import com.yoho.search.recall.beans.strategy.StrategyEnum; | @@ -15,9 +14,12 @@ import com.yoho.search.recall.beans.strategy.StrategyEnum; | ||
15 | import com.yoho.search.recall.models.common.RecallSknInfo; | 14 | import com.yoho.search.recall.models.common.RecallSknInfo; |
16 | import com.yoho.search.recall.models.req.UserRecallRequest; | 15 | import com.yoho.search.recall.models.req.UserRecallRequest; |
17 | import com.yoho.search.recall.models.req.UserRecallResponse; | 16 | import com.yoho.search.recall.models.req.UserRecallResponse; |
17 | +import com.yoho.search.service.base.SearchCommonService; | ||
18 | import com.yoho.search.service.base.SearchRequestParams; | 18 | import com.yoho.search.service.base.SearchRequestParams; |
19 | import org.apache.commons.collections.MapUtils; | 19 | import org.apache.commons.collections.MapUtils; |
20 | -import org.apache.commons.lang.StringUtils; | 20 | +import org.apache.commons.lang3.StringUtils; |
21 | +import org.elasticsearch.index.query.BoolQueryBuilder; | ||
22 | +import org.elasticsearch.index.query.QueryBuilders; | ||
21 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
22 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
23 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -41,6 +43,8 @@ public class RecallResultController { | @@ -41,6 +43,8 @@ public class RecallResultController { | ||
41 | private UserRecallCacheBean userRecallCacheBean; | 43 | private UserRecallCacheBean userRecallCacheBean; |
42 | @Autowired | 44 | @Autowired |
43 | private SknReturnInfoCacheBean sknReturnInfoCacheBean; | 45 | private SknReturnInfoCacheBean sknReturnInfoCacheBean; |
46 | + @Autowired | ||
47 | + private SearchCommonService searchCommonService; | ||
44 | 48 | ||
45 | private List<String> supportPageIdList = Arrays.asList(SearchPageIdDefine.PAGE_ID_SORT, SearchPageIdDefine.PAGE_ID_NEW, SearchPageIdDefine.PAGE_ID_ZQ, SearchPageIdDefine.PAGE_ID_POOL); | 49 | private List<String> supportPageIdList = Arrays.asList(SearchPageIdDefine.PAGE_ID_SORT, SearchPageIdDefine.PAGE_ID_NEW, SearchPageIdDefine.PAGE_ID_ZQ, SearchPageIdDefine.PAGE_ID_POOL); |
46 | 50 | ||
@@ -76,6 +80,24 @@ public class RecallResultController { | @@ -76,6 +80,24 @@ public class RecallResultController { | ||
76 | return recallProductList(paramMap); | 80 | return recallProductList(paramMap); |
77 | } | 81 | } |
78 | 82 | ||
83 | + @RequestMapping(method = RequestMethod.GET, value = "/querySknInfo") | ||
84 | + public SearchApiResult querySknInfo(HttpServletRequest request) { | ||
85 | + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | ||
86 | + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN))) { | ||
87 | + return new SearchApiResult().setCode(400).setMessage("缺少skn"); | ||
88 | + } | ||
89 | + SearchParam searchParam = new SearchParam(); | ||
90 | + BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); | ||
91 | + boolFilter.filter(QueryBuilders.termQuery(ProductIndexEsField.productSkn, paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN))); | ||
92 | + searchParam.setFiter(boolFilter); | ||
93 | + searchParam.setSize(1); | ||
94 | + searchParam.setQuery(QueryBuilders.matchAllQuery()); | ||
95 | + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); | ||
96 | + if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) { | ||
97 | + return new SearchApiResult().setData(searchResult.getResultList().get(0)); | ||
98 | + } | ||
99 | + return new SearchApiResult().setData(null); | ||
100 | + } | ||
79 | 101 | ||
80 | private boolean checkSortParam(Map<String, String> paramMap) { | 102 | private boolean checkSortParam(Map<String, String> paramMap) { |
81 | if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) { | 103 | if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) { |
-
Please register or login to post a comment