|
|
package com.yoho.search.consumer.test;
|
|
|
|
|
|
import com.yoho.search.consumer.job.IndexRebuildJob;
|
|
|
import com.yoho.search.consumer.job.SuggestionCounterJob;
|
|
|
import com.yoho.search.consumer.job.SuggestionDiscoveryJob;
|
|
|
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 SuggestionDiscoveryJob suggestionDiscoveryJob;
|
|
|
|
|
|
@Autowired
|
|
|
private SuggestionCounterJob suggestionCounterJob;
|
|
|
|
|
|
@Autowired
|
|
|
private IndexRebuildJob indexRebuildJob;
|
|
|
|
|
|
@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={}]");
|
|
|
|
|
|
// 1. 清除suggest_word_def表
|
|
|
suggestWordDefService.deleteAllValidKeywords();
|
|
|
logger.info("[func=doUpgrade][msg=deleteAllValidKeywords succeed]");
|
|
|
|
|
|
// 2. 执行SuggestionDiscovery
|
|
|
suggestionDiscoveryJob.execute();
|
|
|
logger.info("[func=doUpgrade][msg=suggestionDiscoveryJob succeed]");
|
|
|
|
|
|
// 3. 执行SuggestionCounter
|
|
|
suggestionCounterJob.execute();
|
|
|
logger.info("[func=doUpgrade][msg=suggestionCounterJob succeed]");
|
|
|
|
|
|
// 4. 重建suggest索引
|
|
|
indexRebuildJob.rebuildSuggestIndex();
|
|
|
logger.info("[func=doUpgrade][msg=rebuildSuggestIndex succeed]");
|
|
|
|
|
|
// 5. 执行SuggestConvertor
|
|
|
spiderJob.convertSpiderContents();
|
|
|
logger.info("[func=doUpgrade][msg=convertSpiderContents succeed]");
|
|
|
|
|
|
// 6. 重建conversion索引
|
|
|
indexRebuildJob.rebuildConversionIndex();
|
|
|
logger.info("[func=doUpgrade][msg=rebuildConversionIndex succeed][cost={}]", System.currentTimeMillis() - begin);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|