Authored by Gino Zhang

支持每天定时爬虫处理

package com.yoho.search.service.restapi;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.yoho.search.service.cache.LocalCacheService;
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
import com.yoho.search.service.service.SearchKeyWordService;
import com.yoho.search.service.servicenew.IProductListService;
import com.yoho.search.service.vo.KeyWordWithCount;
import com.yoho.search.service.vo.SearchApiResult;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
... ... @@ -12,133 +14,142 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.service.cache.LocalCacheService;
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
import com.yoho.search.service.service.SearchKeyWordService;
import com.yoho.search.service.servicenew.IProductListService;
import com.yoho.search.service.vo.KeyWordWithCount;
import com.yoho.search.service.vo.SearchApiResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/tools")
public class ToolsController {
@Autowired
private SearchKeyWordService searchKeyWordService;
@Autowired
private LocalCacheService localCacheService;
@Autowired
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
@Autowired
private IProductListService productListService;
@Autowired
private SearchKeyWordService searchKeyWordService;
@Autowired
private LocalCacheService localCacheService;
@Autowired
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
@Autowired
private IProductListService productListService;
/**
* 获取热搜词结果
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/hotSearchWords")
@ResponseBody
public SearchApiResult hotSearchWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getHotkeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
/**
* 获取热搜词结果
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/hotSearchWords")
@ResponseBody
public SearchApiResult hotSearchWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getHotkeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>)results.get("-1")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取空结果搜索词
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/emptyResultKeywords")
@ResponseBody
public SearchApiResult emptyResultKeywords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getEmptyKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
/**
* 获取空结果搜索词
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/emptyResultKeywords")
@ResponseBody
public SearchApiResult emptyResultKeywords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getEmptyKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>)results.get("-1")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取一页搜索词
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/lessKeyWords")
@ResponseBody
public SearchApiResult lessKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getLessKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
/**
* 获取一页搜索词
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/lessKeyWords")
@ResponseBody
public SearchApiResult lessKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getLessKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>)results.get("-1")) {
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));
}
/**
* 获取分词结果
*
* @param request
* @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);
}
/**
* 获取分词结果
*
* @param request
* @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);
}
/**
* 清除本地缓存
*
* @param request
* 请求
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/clearLocalCache")
@ResponseBody
public SearchApiResult clearLocalCache() {
localCacheService.clearLocalCache();
return new SearchApiResult().setMessage("清除本地缓存成功");
}
/**
* 清除本地缓存
*
* @param request 请求
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/clearLocalCache")
@ResponseBody
public SearchApiResult clearLocalCache() {
localCacheService.clearLocalCache();
return new SearchApiResult().setMessage("清除本地缓存成功");
}
@RequestMapping(method = RequestMethod.GET, value = "/calVectorFeature")
@ResponseBody
public SearchApiResult calVectorFeature(@RequestParam String uid, @RequestParam String skns, @RequestParam String version) throws Exception {
SearchApiResult productListResult = productListService.productListBySknList(skns);
if (productListResult.getCode() != 200) {
return productListResult;
}
@RequestMapping(method = RequestMethod.GET, value = "/calVectorFeature")
@ResponseBody
public SearchApiResult calVectorFeature(@RequestParam String uid, @RequestParam String skns, @RequestParam String version) throws Exception {
SearchApiResult productListResult = productListService.productListBySknList(skns);
if (productListResult.getCode() != 200) {
return productListResult;
}
Map<String, String> productVectorFeatureMap = (Map<String, String>) productListResult.getData();
return new SearchApiResult().setData(personalVectorFeatureSearch.calVectorFeature(uid, version, productVectorFeatureMap));
}
Map<String, String> productVectorFeatureMap = (Map<String, String>) productListResult.getData();
return new SearchApiResult().setData(personalVectorFeatureSearch.calVectorFeature(uid, version, productVectorFeatureMap));
}
}
... ...
... ... @@ -212,4 +212,14 @@ public class SearchKeyWordService {
}
}
public String deleteRedisKey(String redisKey){
if(yhNoSyncRedisTemplate.hasKey(redisKey)){
yhNoSyncRedisTemplate.delete(redisKey);
return "The key has been deleted succede!";
}
else{
return "The key doesn't exist.";
}
}
}
... ...