ToolsController.java
8.6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package com.yoho.search.restapi.tools;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.common.utils.LogUtils;
import com.yoho.search.models.KeyWordWithCount;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.scene.UserVectorSortBrandService;
import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
import com.yoho.search.service.service.IProductListService;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/tools")
public class ToolsController {
@Autowired
private SearchKeyWordHelper searchKeyWordService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Autowired
private UserVectorSortBrandService userVectorSortBrandService;
/**
* 获取热搜词结果
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/hotSearchWords")
@ResponseBody
public SearchApiResult hotSearchWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getHotkeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取空结果搜索词
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/emptyResultKeywords")
@ResponseBody
public SearchApiResult emptyResultKeywords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getEmptyKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取一页搜索词
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/lessKeyWords")
@ResponseBody
public SearchApiResult lessKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getLessKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取需要推荐的关键词
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/recomKeyWords")
@ResponseBody
public SearchApiResult recomKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getNeedRecomKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 删除redis上的key
*
* @param redisKey
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/deleteRedis")
@ResponseBody
public SearchApiResult deleteRedisKey(@RequestParam String redisKey) {
SearchApiResult searchApiResult = new SearchApiResult();
return searchApiResult.setData(searchKeyWordService.deleteRedisKey(redisKey));
}
/**
* 获取分词结果
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/analyzeTokens")
@ResponseBody
public SearchApiResult onePageKeywords(@RequestParam(defaultValue = "") String text, @RequestParam(defaultValue = "ik_complex") String analyzer) {
List<AnalyzeToken> analyzeTokens = searchKeyWordService.getAnalyzeTokens(text, analyzer);
SearchApiResult searchApiResult = new SearchApiResult();
return searchApiResult.setData(analyzeTokens);
}
/**
* 获取zk上动态配置的结果
* @param key
* @return
*/
@RequestMapping(value = "/dynamicParameterValue")
@ResponseBody
public Map<String, Object> dynamicParameterValue(String key) {
Map<String, Object> rtnMap = new HashMap<String, Object>();
try {
rtnMap.put("code", 200);
rtnMap.put("value", searchDynamicConfigService.getDynamicParameterValue(key));
} catch (Exception e) {
rtnMap.put("code", 400);
rtnMap.put("msg", e.getMessage());
}
return rtnMap;
}
/**
* 用于动态地变更日记级别。
* @param loggerName 日志名称,有三类:
* 第一种是ROOT,对所有日志都起作用,
* 第二种是具体的日志名称,如CACHE_MATCH_REQUEST,
* 第三种就是全限定类名,如com.yoho.search.service.servicenew.impl.ProductListServiceImpl。
* @param level 调整目标级别,支持ALL/TRACE/DEBUG/INFO/WARN/ERROR/OFF这些取值
* @param seconds 调整日志级别的有效时间,默认为60秒,最多只能为300秒,到了时间后变更为原来的日志级别。
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/changeLogLevel")
@ResponseBody
public SearchApiResult changeLogLevel(@RequestParam(defaultValue = "ROOT") String loggerName,
@RequestParam(defaultValue = "INFO") String level,
@RequestParam(defaultValue = "60") int seconds) {
try {
return new SearchApiResult().setData(LogUtils.changeLogLevel(loggerName, level, seconds));
} catch (Exception e) {
return new SearchApiResult().setCode(500).setMessage(e.getMessage());
}
}
/**
* 获取用户根据向量预测出来的品类品牌
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/userVectorSortBrand")
@ResponseBody
public SearchApiResult userVectorSortBrand(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return userVectorSortBrandService.userVectorSortBrand(paramMap);
}
}