Authored by Zhao

add searchcacbeale to helper and robotquestion

package com.yoho.search.restapi.others;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IHelperService;
... ... @@ -30,6 +31,7 @@ public class HelperController {
* @return
* @author wangnan
*/
@SearchCacheAble(cacheInMinute = 10, cacheName = "helperController_searchHelper")
@RequestMapping(method = RequestMethod.GET, value = "/helper")
@ResponseBody
public SearchApiResult searchHelper(HttpServletRequest request) {
... ...
package com.yoho.search.restapi.others;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IRobotQuestionService;
... ... @@ -29,6 +30,7 @@ public class RobotQuestionController {
* @param request
* @return
*/
@SearchCacheAble(cacheInMinute = 10, cacheName = "robotQuestionController_searchRobotQuestion")
@RequestMapping(method = RequestMethod.GET, value = "/robotquestion")
@ResponseBody
public SearchApiResult searchRobotQuestion(HttpServletRequest request) {
... ...
... ... @@ -102,7 +102,9 @@ public class MergeFiles {
public static String replaceUid(String url) {
url = url.replaceAll("uid=", "");// 去除order
url = url.replaceAll("&&", "&");// 去除order
url = url + "&uid=" + uids.get((int) (Math.random() * uids.size()));
if (uids.size() > 0) {
url = url + "&uid=" + uids.get((int) (Math.random() * uids.size()));
}
return url;
}
... ...
... ... @@ -14,5 +14,5 @@ public interface IHelperService {
* @param paramMap
* @return
*/
public SearchApiResult helper(Map<String, String> paramMap);
SearchApiResult helper(Map<String, String> paramMap);
}
... ...
... ... @@ -14,5 +14,5 @@ public interface IRobotQuestionService {
* @param paramMap
* @return
*/
public SearchApiResult robotQuestion(Map<String, String> paramMap);
SearchApiResult robotQuestion(Map<String, String> paramMap);
}
... ...
... ... @@ -115,13 +115,7 @@ public class HelperServiceImpl extends BaseService implements IHelperService, Ap
sortBuilders.add(SortBuilders.scoreSort());
searchParam.setSortBuilders(sortBuilders);
// 6.走本地缓存
final String indexName = ISearchConstants.INDEX_NAME_HELPER;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(searchCache,indexName, searchParam);
if (cacheObject != null) {
CACHE_MATCH_REQUEST.info("match cache , url is :/helper.json? {}" , HttpServletRequestUtils.genParamString(paramMap));
return new SearchApiResult().setData(cacheObject);
}
// 7.查询ES
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
SearchApiResult searchApiResult = new SearchApiResult();
... ... @@ -136,7 +130,6 @@ public class HelperServiceImpl extends BaseService implements IHelperService, Ap
dataMap.put("page_size", searchParam.getSize());
dataMap.put("page_total", searchResult.getTotalPage());
dataMap.put("helper_list", getHelperMap(searchResult.getResultList()));
searchCacheService.addJSONObjectToCache(searchCache,indexName, searchParam, dataMap);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_HELPER.getEventName(), EventReportEnum.SEARCHCONTROLLER_HELPER.getFunctionName(),
... ...
... ... @@ -55,9 +55,6 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private SearchCacheFactory searchCacheFactory;
private SearchCache searchCache;
... ... @@ -130,14 +127,7 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest
sortBuilders.add(SortBuilders.fieldSort("questionSeq").order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 6.走本地缓存
final String indexName = ISearchConstants.INDEX_NAME_ROBOTQUESTION;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(searchCache, indexName, searchParam);
if (cacheObject != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/robotquestion.json", paramMap);
return new SearchApiResult().setData(cacheObject);
}
// 7.查询ES
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
SearchApiResult searchApiResult = new SearchApiResult();
... ... @@ -151,7 +141,6 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest
dataMap.put("page_size", searchParam.getSize());
dataMap.put("page_total", searchResult.getTotalPage());
dataMap.put("answer_list", this.getRobotQuestionMap(searchResult.getResultList()));
searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, dataMap);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_ROBOTQUESTION.getEventName(), EventReportEnum.SEARCHCONTROLLER_ROBOTQUESTION.getFunctionName(),
... ...