UfoResultController.java
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.yoho.search.restapi.tools;
import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.common.BaseSceneService;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.others.explain.SearchExplainerService;
import com.yoho.search.service.scene.others.explain.UfoSearchExplainerService;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@RestController
@RequestMapping(value = "/tools")
public class UfoResultController extends BaseSceneService {
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private UfoSearchExplainerService ufoSearchExplainerService;
/**
* 根据ufo code查询商品索引信息
*/
@RequestMapping(method = RequestMethod.GET, value = "/queryUfoSknInfo")
public SearchApiResult queryUfoSknInfo(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFO_PARAM_PRODUCT_CODE))) {
return new SearchApiResult().setCode(400).setMessage("缺少skn");
}
SearchParam searchParam = new SearchParam();
searchParam.setSize(1);
searchParam.setQuery(QueryBuilders.matchQuery(UfoProductIndexEsField.productCode, paramMap.get(UfoSearchRequestParams.UFO_PARAM_PRODUCT_CODE)));
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
return new SearchApiResult().setData(searchResult.getResultList().get(0));
}
return new SearchApiResult().setData(null);
}
/**
* 显示ufo分词结果
*/
@RequestMapping(value = "/ufoShow")
public Map<String, Object> ufoShow(HttpServletRequest request) {
Map<String, String> paramMap = com.yoho.search.base.utils.HttpServletRequestUtils.transParamType(request);
try {
return ufoSearchExplainerService.ufoShow(paramMap);
} catch (Throwable t) {
return new HashMap<>();
}
}
}