UpgradeSearchConsumerController.java
2.15 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
package com.yoho.search.consumer.test;
import com.yoho.search.consumer.job.SuggestionJob;
import com.yoho.search.consumer.service.base.SuggestWordDefService;
import com.yoho.search.spider.job.SpiderJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ResponseBody;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ginozhang on 2017/3/10.
*/
@Controller
public class UpgradeSearchConsumerController {
private static final Logger logger = LoggerFactory.getLogger(UpgradeSearchConsumerController.class);
@Autowired
private SuggestWordDefService suggestWordDefService;
@Autowired
private SuggestionJob suggestionJob;
@Autowired
private SpiderJob spiderJob;
@RequestMapping(value = "/proteced/upgrade")
@ResponseBody
public Map<String, Object> upgrade() {
Map<String, Object> rtnMap = new HashMap<String, Object>();
try {
doUpgrade();
rtnMap.put("code", 200);
rtnMap.put("msg", "success");
} catch (Exception e) {
logger.error(e.getMessage(), e);
rtnMap.put("code", 500);
rtnMap.put("msg", e.getMessage());
}
return rtnMap;
}
private void doUpgrade() {
// Important NOTE: 本升级restful 接口为2017.03.13升级所写 升级后可删除
long begin = System.currentTimeMillis();
logger.info("[func=doUpgrade][begin={}]", begin);
// 1. 清除suggest_word_def表
suggestWordDefService.deleteAllValidKeywords();
logger.info("[func=doUpgrade][msg=deleteAllValidKeywords succeed]");
// 2. 执行SuggestionDiscovery/SuggestionCounter/SuggestIndexRebuilder
suggestionJob.executeAll();
// 3. 执行SuggestConvertor/conversion索引的重建
spiderJob.convertAndRebuildIndex();
logger.info("[func=doUpgrade][msg=convertAndRebuildIndex succeed][cost={}]", System.currentTimeMillis() - begin);
}
}