Authored by unknown

Merge branch 'master' into new_list

@@ -12,11 +12,15 @@ public class SearchCacheMatchLogger { @@ -12,11 +12,15 @@ public class SearchCacheMatchLogger {
12 private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST"); 12 private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
13 13
14 public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) { 14 public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) {
15 - CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap)); 15 + if(CACHE_MATCH_REQUEST.isInfoEnabled()){
  16 + CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap));
  17 + }
16 } 18 }
17 19
18 public static void doSearchCacheMatchLog(String method, String key) { 20 public static void doSearchCacheMatchLog(String method, String key) {
19 - CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key); 21 + if(CACHE_MATCH_REQUEST.isInfoEnabled()){
  22 + CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key);
  23 + }
20 } 24 }
21 25
22 } 26 }
1 package com.yoho.search.common.interceptor; 1 package com.yoho.search.common.interceptor;
2 2
  3 +import javax.annotation.PostConstruct;
3 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse; 5 import javax.servlet.http.HttpServletResponse;
5 6
@@ -12,6 +13,7 @@ import org.springframework.web.servlet.ModelAndView; @@ -12,6 +13,7 @@ import org.springframework.web.servlet.ModelAndView;
12 13
13 import com.yoho.core.common.monitor.ThreadProfile; 14 import com.yoho.core.common.monitor.ThreadProfile;
14 import com.yoho.core.common.utils.HttpRequestUtils; 15 import com.yoho.core.common.utils.HttpRequestUtils;
  16 +import com.yoho.search.base.monitor.PerformanceMonitor;
15 import com.yoho.search.common.downgrade.DownGradeService; 17 import com.yoho.search.common.downgrade.DownGradeService;
16 import com.yoho.search.common.utils.HttpServletRequestUtils; 18 import com.yoho.search.common.utils.HttpServletRequestUtils;
17 19
@@ -23,14 +25,21 @@ import com.yoho.search.common.utils.HttpServletRequestUtils; @@ -23,14 +25,21 @@ import com.yoho.search.common.utils.HttpServletRequestUtils;
23 public class ControllerCostInterceptor implements HandlerInterceptor { 25 public class ControllerCostInterceptor implements HandlerInterceptor {
24 26
25 private static final Logger CONTROLLER_COST = LoggerFactory.getLogger("CONTROLLER_COST"); 27 private static final Logger CONTROLLER_COST = LoggerFactory.getLogger("CONTROLLER_COST");
  28 +
  29 + private static final Logger CONTROLLER_PERFORMANCE = LoggerFactory.getLogger("CONTROLLER_PERFORMANCE");
26 30
27 private static final ThreadLocal<Long> startTimeThreadLocal = new NamedThreadLocal<Long>("ThreadLocal StartTime"); 31 private static final ThreadLocal<Long> startTimeThreadLocal = new NamedThreadLocal<Long>("ThreadLocal StartTime");
28 -  
29 - @Autowired  
30 - private PerformanceMonitor monitor; 32 +
31 @Autowired 33 @Autowired
32 private DownGradeService downGradeService; 34 private DownGradeService downGradeService;
  35 +
  36 + private PerformanceMonitor monitor;
33 37
  38 + @PostConstruct
  39 + void init(){
  40 + monitor = new PerformanceMonitor("CONTROLLER_PERFORMANCE",CONTROLLER_PERFORMANCE, 10);
  41 + }
  42 +
34 @Override 43 @Override
35 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handle) throws Exception { 44 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handle) throws Exception {
36 long beginTime = System.currentTimeMillis();// 1、开始时间 45 long beginTime = System.currentTimeMillis();// 1、开始时间
1 -package com.yoho.search.common.interceptor;  
2 -  
3 -import java.util.concurrent.Executors;  
4 -import java.util.concurrent.ScheduledExecutorService;  
5 -import java.util.concurrent.TimeUnit;  
6 -import java.util.concurrent.atomic.AtomicLong;  
7 -  
8 -import javax.annotation.PostConstruct;  
9 -  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.stereotype.Component;  
13 -  
14 -@Component  
15 -public class PerformanceMonitor {  
16 -  
17 - private static final Logger logger = LoggerFactory.getLogger(PerformanceMonitor.class);  
18 - private static final Logger CONTROLLER_PERFORMANCE = LoggerFactory.getLogger("CONTROLLER_PERFORMANCE");  
19 -  
20 - private AtomicLong totalVisit = new AtomicLong(0);  
21 - private AtomicLong totalCost = new AtomicLong(0);  
22 -  
23 - private AtomicLong over500msCount = new AtomicLong(0);  
24 - private AtomicLong over1000msCount = new AtomicLong(0);  
25 -  
26 - private final int MonitorPeriodInSecond = 10;  
27 -  
28 - private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();  
29 -  
30 - @PostConstruct  
31 - void init() {  
32 - scheduledExecutorService.scheduleAtFixedRate(new Runnable() {  
33 - @Override  
34 - public void run() {  
35 - logAndClear();  
36 - }  
37 - }, 0, MonitorPeriodInSecond, TimeUnit.SECONDS);  
38 - }  
39 -  
40 - private void logAndClear() {  
41 - try {  
42 - long visitCount = totalVisit.longValue();  
43 - long vostMs = totalCost.longValue();  
44 - long average = visitCount == 0 ? 0 : (vostMs / visitCount);  
45 - long over500msCnt = over500msCount.longValue();  
46 - double over500msCntPercent = visitCount == 0 ? 0 : (over500msCnt * 100L / visitCount);  
47 - long over1000msCnt = over1000msCount.longValue();  
48 - double over1000msCntPercent = visitCount == 0 ? 0 : (over1000msCnt * 100L / visitCount);  
49 - CONTROLLER_PERFORMANCE.info("Performance.Monitoring,Peroid [{}]s,totalVisit[{}],totalCost[{}] ms,AverageCost[{}]ms,over500msCount[{}][{}%],over1000msCnt[{}][{}%]", MonitorPeriodInSecond, visitCount,  
50 - vostMs, average,over500msCnt,over500msCntPercent,over1000msCnt,over1000msCntPercent);  
51 - totalVisit.set(0);  
52 - totalCost.set(0);  
53 - over500msCount.set(0);  
54 - over1000msCount.set(0);  
55 - } catch (Exception e) {  
56 - logger.error(e.getMessage(), e);  
57 - }  
58 - }  
59 -  
60 - public void addVisitCount() {  
61 - totalVisit.incrementAndGet();  
62 - }  
63 -  
64 - public void addCost(long cost) {  
65 - totalCost.addAndGet(cost);  
66 - if(cost>=1000){  
67 - over1000msCount.incrementAndGet();  
68 - }  
69 - if(cost>=500){  
70 - over500msCount.incrementAndGet();  
71 - }  
72 - }  
73 -  
74 -}  
@@ -8,17 +8,22 @@ import java.util.List; @@ -8,17 +8,22 @@ import java.util.List;
8 import java.util.Map; 8 import java.util.Map;
9 import java.util.Set; 9 import java.util.Set;
10 10
  11 +import javax.annotation.PostConstruct;
  12 +
11 import org.apache.commons.lang.StringUtils; 13 import org.apache.commons.lang.StringUtils;
12 import org.elasticsearch.action.get.GetResponse; 14 import org.elasticsearch.action.get.GetResponse;
13 import org.elasticsearch.action.get.MultiGetItemResponse; 15 import org.elasticsearch.action.get.MultiGetItemResponse;
14 import org.elasticsearch.action.get.MultiGetResponse; 16 import org.elasticsearch.action.get.MultiGetResponse;
15 import org.elasticsearch.index.query.QueryBuilder; 17 import org.elasticsearch.index.query.QueryBuilder;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
16 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.context.ApplicationEventPublisher; 21 import org.springframework.context.ApplicationEventPublisher;
18 import org.springframework.context.ApplicationEventPublisherAware; 22 import org.springframework.context.ApplicationEventPublisherAware;
19 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
20 24
21 import com.yoho.error.event.SearchEvent; 25 import com.yoho.error.event.SearchEvent;
  26 +import com.yoho.search.base.monitor.PerformanceMonitor;
22 import com.yoho.search.base.utils.EventReportEnum; 27 import com.yoho.search.base.utils.EventReportEnum;
23 import com.yoho.search.core.es.IElasticsearchClient; 28 import com.yoho.search.core.es.IElasticsearchClient;
24 import com.yoho.search.core.es.impl.YohoIndexHelper; 29 import com.yoho.search.core.es.impl.YohoIndexHelper;
@@ -28,13 +33,21 @@ import com.yoho.search.core.es.model.SearchResult; @@ -28,13 +33,21 @@ import com.yoho.search.core.es.model.SearchResult;
28 @Service 33 @Service
29 public class SearchCommonService implements ApplicationEventPublisherAware { 34 public class SearchCommonService implements ApplicationEventPublisherAware {
30 35
  36 + private static final Logger ES_PERFORMANCE = LoggerFactory.getLogger("ES_PERFORMANCE");
  37 +
31 @Autowired 38 @Autowired
32 private ESClientMgr esClientMgr; 39 private ESClientMgr esClientMgr;
33 @Autowired 40 @Autowired
34 private YohoIndexHelper yohoIndexHelper; 41 private YohoIndexHelper yohoIndexHelper;
35 42
36 private ApplicationEventPublisher publisher; 43 private ApplicationEventPublisher publisher;
37 - 44 + private PerformanceMonitor performanceMonitor;
  45 +
  46 + @PostConstruct
  47 + void init(){
  48 + performanceMonitor = new PerformanceMonitor("ES_PERFORMANCE",ES_PERFORMANCE, 10);
  49 + }
  50 +
38 @Override 51 @Override
39 public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { 52 public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
40 this.publisher = applicationEventPublisher; 53 this.publisher = applicationEventPublisher;
@@ -65,12 +78,20 @@ public class SearchCommonService implements ApplicationEventPublisherAware { @@ -65,12 +78,20 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
65 * @return 78 * @return
66 */ 79 */
67 public SearchResult doSearch(final String indexName, final SearchParam searchParam) { 80 public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
68 - IElasticsearchClient client = esClientMgr.getClient(indexName);  
69 - SearchResult searchResult = client.search(indexName, indexName, searchParam);  
70 - this.publishSearchResultEvent(indexName, searchParam, searchResult);  
71 - return searchResult; 81 + long begin = System.currentTimeMillis();
  82 + performanceMonitor.addVisitCount();
  83 + try {
  84 + IElasticsearchClient client = esClientMgr.getClient(indexName);
  85 + SearchResult searchResult = client.search(indexName, indexName, searchParam);
  86 + this.publishSearchResultEvent(indexName, searchParam, searchResult);
  87 + return searchResult;
  88 + } catch (Exception e) {
  89 + throw e;
  90 + }finally{
  91 + performanceMonitor.addCost(System.currentTimeMillis() - begin);
  92 + }
72 } 93 }
73 - 94 +
74 /** 95 /**
75 * 根据多个索引查询 96 * 根据多个索引查询
76 * 97 *
@@ -79,10 +100,18 @@ public class SearchCommonService implements ApplicationEventPublisherAware { @@ -79,10 +100,18 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
79 * @return 100 * @return
80 */ 101 */
81 public SearchResult doSearch(final List<String> indexNames, final SearchParam searchParam) { 102 public SearchResult doSearch(final List<String> indexNames, final SearchParam searchParam) {
82 - IElasticsearchClient client = esClientMgr.getClient(indexNames.get(0));  
83 - SearchResult searchResult = client.search(indexNames, indexNames, searchParam);  
84 - this.publishSearchResultEvent(indexNames.toString(), searchParam, searchResult);  
85 - return searchResult; 103 + long begin = System.currentTimeMillis();
  104 + performanceMonitor.addVisitCount();
  105 + try {
  106 + IElasticsearchClient client = esClientMgr.getClient(indexNames.get(0));
  107 + SearchResult searchResult = client.search(indexNames, indexNames, searchParam);
  108 + this.publishSearchResultEvent(indexNames.toString(), searchParam, searchResult);
  109 + return searchResult;
  110 + } catch (Exception e) {
  111 + throw e;
  112 + }finally{
  113 + performanceMonitor.addCost(System.currentTimeMillis() - begin);
  114 + }
86 } 115 }
87 116
88 /** 117 /**
@@ -93,17 +122,25 @@ public class SearchCommonService implements ApplicationEventPublisherAware { @@ -93,17 +122,25 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
93 * @return 122 * @return
94 */ 123 */
95 public List<SearchResult> doMutiSearch(final String indexName, final List<SearchParam> searchParams) { 124 public List<SearchResult> doMutiSearch(final String indexName, final List<SearchParam> searchParams) {
96 - if (searchParams == null || searchParams.isEmpty()) {  
97 - return new ArrayList<SearchResult>();  
98 - }  
99 - IElasticsearchClient client = esClientMgr.getClient(indexName);  
100 - List<SearchResult> results = client.multiSearch(indexName, indexName, searchParams);  
101 - for (int i = 0; i < searchParams.size(); i++) {  
102 - SearchResult searchResult = results.get(i);  
103 - SearchParam searchParam = searchParams.get(i);  
104 - this.publishSearchResultEvent(indexName, searchParam, searchResult); 125 + long begin = System.currentTimeMillis();
  126 + performanceMonitor.addVisitCount(searchParams==null?0:searchParams.size());
  127 + try {
  128 + if (searchParams == null || searchParams.isEmpty()) {
  129 + return new ArrayList<SearchResult>();
  130 + }
  131 + IElasticsearchClient client = esClientMgr.getClient(indexName);
  132 + List<SearchResult> results = client.multiSearch(indexName, indexName, searchParams);
  133 + for (int i = 0; i < searchParams.size(); i++) {
  134 + SearchResult searchResult = results.get(i);
  135 + SearchParam searchParam = searchParams.get(i);
  136 + this.publishSearchResultEvent(indexName, searchParam, searchResult);
  137 + }
  138 + return results;
  139 + } catch (Exception e) {
  140 + throw e;
  141 + }finally{
  142 + performanceMonitor.addCost(System.currentTimeMillis() - begin);
105 } 143 }
106 - return results;  
107 } 144 }
108 145
109 /** 146 /**
@@ -114,20 +151,28 @@ public class SearchCommonService implements ApplicationEventPublisherAware { @@ -114,20 +151,28 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
114 * @return 151 * @return
115 */ 152 */
116 public Map<String, Object> doGetCommon(final String indexName, final String id) { 153 public Map<String, Object> doGetCommon(final String indexName, final String id) {
117 - if (StringUtils.isBlank(id)) {  
118 - return null;  
119 - }  
120 - IElasticsearchClient client = esClientMgr.getClient(indexName);  
121 - List<String> realIndexNames = yohoIndexHelper.getRealIndexNames(indexName, client);  
122 - if (realIndexNames == null || realIndexNames.isEmpty()) {  
123 - return null;  
124 - }  
125 - GetResponse response = client.get(realIndexNames.get(0), indexName, id);  
126 - // 判断是否为空  
127 - if (response == null || response.getSource() == null || response.getSource().isEmpty()) {  
128 - return null; 154 + long begin = System.currentTimeMillis();
  155 + performanceMonitor.addVisitCount(StringUtils.isBlank(id)?0:1);
  156 + try {
  157 + if (StringUtils.isBlank(id)) {
  158 + return null;
  159 + }
  160 + IElasticsearchClient client = esClientMgr.getClient(indexName);
  161 + List<String> realIndexNames = yohoIndexHelper.getRealIndexNames(indexName, client);
  162 + if (realIndexNames == null || realIndexNames.isEmpty()) {
  163 + return null;
  164 + }
  165 + GetResponse response = client.get(realIndexNames.get(0), indexName, id);
  166 + // 判断是否为空
  167 + if (response == null || response.getSource() == null || response.getSource().isEmpty()) {
  168 + return null;
  169 + }
  170 + return response.getSourceAsMap();
  171 + } catch (Exception e) {
  172 + throw e;
  173 + }finally{
  174 + performanceMonitor.addCost(System.currentTimeMillis() - begin);
129 } 175 }
130 - return response.getSourceAsMap();  
131 } 176 }
132 177
133 /** 178 /**
@@ -137,26 +182,34 @@ public class SearchCommonService implements ApplicationEventPublisherAware { @@ -137,26 +182,34 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
137 * @return 182 * @return
138 */ 183 */
139 public List<Map<String, Object>> doMultiGetCommon(final String indexName, final Collection<?> idList) throws Exception { 184 public List<Map<String, Object>> doMultiGetCommon(final String indexName, final Collection<?> idList) throws Exception {
140 - if (idList == null || idList.isEmpty()) {  
141 - return new ArrayList<Map<String, Object>>();  
142 - }  
143 - IElasticsearchClient client = esClientMgr.getClient(indexName);  
144 - List<String> realIndexNames = yohoIndexHelper.getRealIndexNames(indexName, client);  
145 - if (realIndexNames == null || realIndexNames.isEmpty()) {  
146 - return new ArrayList<Map<String, Object>>();  
147 - }  
148 - Set<String> idSet = new HashSet<String>();  
149 - for (Object id : idList) {  
150 - idSet.add(id.toString());  
151 - }  
152 - MultiGetResponse response = client.multiGet(realIndexNames.get(0), indexName, idSet, null);  
153 - List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();  
154 - for (MultiGetItemResponse item : response.getResponses()) {  
155 - if (item.getResponse().isExists()) {  
156 - results.add(item.getResponse().getSource()); 185 + long begin = System.currentTimeMillis();
  186 + performanceMonitor.addVisitCount(idList==null||idList.isEmpty()?0:1);
  187 + try {
  188 + if (idList == null || idList.isEmpty()) {
  189 + return new ArrayList<Map<String, Object>>();
  190 + }
  191 + IElasticsearchClient client = esClientMgr.getClient(indexName);
  192 + List<String> realIndexNames = yohoIndexHelper.getRealIndexNames(indexName, client);
  193 + if (realIndexNames == null || realIndexNames.isEmpty()) {
  194 + return new ArrayList<Map<String, Object>>();
  195 + }
  196 + Set<String> idSet = new HashSet<String>();
  197 + for (Object id : idList) {
  198 + idSet.add(id.toString());
  199 + }
  200 + MultiGetResponse response = client.multiGet(realIndexNames.get(0), indexName, idSet, null);
  201 + List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
  202 + for (MultiGetItemResponse item : response.getResponses()) {
  203 + if (item.getResponse().isExists()) {
  204 + results.add(item.getResponse().getSource());
  205 + }
157 } 206 }
  207 + return results;
  208 + } catch (Exception e) {
  209 + throw e;
  210 + }finally{
  211 + performanceMonitor.addCost(System.currentTimeMillis() - begin);
158 } 212 }
159 - return results;  
160 } 213 }
161 214
162 } 215 }
1 package com.yoho.search.service.scene; 1 package com.yoho.search.service.scene;
2 2
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +import java.util.concurrent.CompletableFuture;
  6 +import java.util.concurrent.ExecutorService;
  7 +import java.util.concurrent.Executors;
  8 +
  9 +import org.apache.commons.lang.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
3 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.SearchPageIdDefine; 16 import com.yoho.search.base.utils.SearchPageIdDefine;
5 import com.yoho.search.common.utils.SearchApiResultUtils; 17 import com.yoho.search.common.utils.SearchApiResultUtils;
@@ -14,18 +26,6 @@ import com.yoho.search.service.scene.common.SceneSelectionsService; @@ -14,18 +26,6 @@ import com.yoho.search.service.scene.common.SceneSelectionsService;
14 import com.yoho.search.service.service.IAggRecommendService; 26 import com.yoho.search.service.service.IAggRecommendService;
15 import com.yoho.search.service.service.IProductIndexService; 27 import com.yoho.search.service.service.IProductIndexService;
16 import com.yoho.search.service.service.ISearchRecommendService; 28 import com.yoho.search.service.service.ISearchRecommendService;
17 -import org.apache.commons.lang.StringUtils;  
18 -import org.slf4j.Logger;  
19 -import org.slf4j.LoggerFactory;  
20 -import org.springframework.beans.factory.annotation.Autowired;  
21 -import org.springframework.stereotype.Service;  
22 -  
23 -import java.util.List;  
24 -import java.util.Map;  
25 -import java.util.concurrent.CompletableFuture;  
26 -import java.util.concurrent.ConcurrentHashMap;  
27 -import java.util.concurrent.ExecutorService;  
28 -import java.util.concurrent.Executors;  
29 29
30 @Service 30 @Service
31 public class FuzzySceneService extends AbstractSceneService { 31 public class FuzzySceneService extends AbstractSceneService {
@@ -44,12 +44,12 @@ public class FuzzySceneService extends AbstractSceneService { @@ -44,12 +44,12 @@ public class FuzzySceneService extends AbstractSceneService {
44 private SearchDynamicConfigService searchDynamicConfigService; 44 private SearchDynamicConfigService searchDynamicConfigService;
45 @Autowired 45 @Autowired
46 private SearchKeyWordHelper searchKeyWordService; 46 private SearchKeyWordHelper searchKeyWordService;
47 - @Autowired  
48 - private IProductIndexService productIndexService;  
49 @Autowired 47 @Autowired
50 - private IAggRecommendService aggRecommendService; 48 + private IProductIndexService productIndexService;
  49 + @Autowired
  50 + private IAggRecommendService recommendService;
51 51
52 - private ExecutorService executorService = Executors.newFixedThreadPool(100); 52 + private ExecutorService executor = Executors.newFixedThreadPool(100);
53 53
54 // 当少于20个商品时 返回智能搜索词提示 54 // 当少于20个商品时 返回智能搜索词提示
55 private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; 55 private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20;
@@ -81,29 +81,30 @@ public class FuzzySceneService extends AbstractSceneService { @@ -81,29 +81,30 @@ public class FuzzySceneService extends AbstractSceneService {
81 // 2、添加默认参数 81 // 2、添加默认参数
82 this.addParamsToParamMap(paramMap); 82 this.addParamsToParamMap(paramMap);
83 // 3、获取商品列表 83 // 3、获取商品列表
84 - SearchApiResult searchApiResult = sceneProductListService.productList(paramMap);  
85 - // 4、加入建议词  
86 - this.addSuggestion(searchApiResult, paramMap);  
87 - // 5、模糊搜索页记录关键字对应的查询结果 84 + CompletableFuture<SearchApiResult> productListuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executor);
  85 + // 4、获取自定义标签聚合结果
  86 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)), executor);
  87 + // 5、获取促销专题
  88 + CompletableFuture<List<Object>> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> recommendService.recommendPromotion(this.newParamMap(paramMap)),
  89 + executor);
  90 +
  91 + // 6、加入建议词
  92 + SearchApiResult productListResult = productListuture.get();
  93 + this.addSuggestion(productListResult, paramMap);
  94 +
  95 + // 7、模糊搜索页记录关键字对应的查询结果
88 String queryWord = paramMap.get("query"); 96 String queryWord = paramMap.get("query");
89 if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) { 97 if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
90 - long total = ((JSONObject) searchApiResult.getData()).getLongValue("total"); 98 + long total = ((JSONObject) productListResult.getData()).getLongValue("total");
91 searchKeyWordService.recordKeyWordByResultCount(queryWord, total); 99 searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
92 } 100 }
93 -  
94 - ConcurrentHashMap<String, String> syncParamMap = new ConcurrentHashMap<>(paramMap);  
95 - // 6、获取自定义标签聚合结果  
96 - CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(syncParamMap), executorService);  
97 -  
98 - CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(syncParamMap), executorService);  
99 -  
100 - SearchApiResult customizeTags = customizeTagFuture.get();  
101 - List<Object> recommendProducts = recommendProductFuture.get();  
102 -  
103 - JSONObject dataMap = (JSONObject)searchApiResult.getData();  
104 - dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); 101 + // 8、组合结果
  102 + SearchApiResult customizeTags = customizeTagFuture.get();
  103 + List<Object> recommendProducts = recommendPromotionFuture.get();
  104 + JSONObject dataMap = (JSONObject) productListResult.getData();
  105 + dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
105 dataMap.put(RECOMMEND_PROMOTION_LIST, recommendProducts); 106 dataMap.put(RECOMMEND_PROMOTION_LIST, recommendProducts);
106 - return searchApiResult; 107 + return productListResult;
107 } catch (Exception e) { 108 } catch (Exception e) {
108 logger.error(e.getMessage(), e); 109 logger.error(e.getMessage(), e);
109 return SearchApiResultUtils.errorSearchApiResult("fuzzyProductList", paramMap, e); 110 return SearchApiResultUtils.errorSearchApiResult("fuzzyProductList", paramMap, e);
@@ -41,7 +41,7 @@ public class ReducePriceSceneService extends AbstractSceneService { @@ -41,7 +41,7 @@ public class ReducePriceSceneService extends AbstractSceneService {
41 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y"); 41 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y");
42 // 默认一周降价 42 // 默认一周降价
43 long end = DateUtil.getLastTimeSecond(new Date()); 43 long end = DateUtil.getLastTimeSecond(new Date());
44 - long begin = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -365)); 44 + long begin = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -7));
45 paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end); 45 paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end);
46 } 46 }
47 47
1 package com.yoho.search.service.scene; 1 package com.yoho.search.service.scene;
2 2
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +import java.util.concurrent.CompletableFuture;
  6 +import java.util.concurrent.ExecutorService;
  7 +import java.util.concurrent.Executors;
  8 +
  9 +import org.apache.commons.lang.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
3 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.SearchPageIdDefine; 16 import com.yoho.search.base.utils.SearchPageIdDefine;
5 import com.yoho.search.models.SearchApiResult; 17 import com.yoho.search.models.SearchApiResult;
@@ -10,21 +22,6 @@ import com.yoho.search.service.scene.common.SceneProductListService; @@ -10,21 +22,6 @@ import com.yoho.search.service.scene.common.SceneProductListService;
10 import com.yoho.search.service.scene.common.SceneSelectionsService; 22 import com.yoho.search.service.scene.common.SceneSelectionsService;
11 import com.yoho.search.service.service.IAggRecommendService; 23 import com.yoho.search.service.service.IAggRecommendService;
12 import com.yoho.search.service.service.IProductIndexService; 24 import com.yoho.search.service.service.IProductIndexService;
13 -import org.apache.commons.collections.MapUtils;  
14 -import org.apache.commons.lang.StringUtils;  
15 -import org.slf4j.Logger;  
16 -import org.slf4j.LoggerFactory;  
17 -import org.springframework.beans.factory.annotation.Autowired;  
18 -import org.springframework.stereotype.Service;  
19 -  
20 -import java.util.ArrayList;  
21 -import java.util.Iterator;  
22 -import java.util.List;  
23 -import java.util.Map;  
24 -import java.util.concurrent.CompletableFuture;  
25 -import java.util.concurrent.ConcurrentHashMap;  
26 -import java.util.concurrent.ExecutorService;  
27 -import java.util.concurrent.Executors;  
28 25
29 @Service 26 @Service
30 public class SortSceneService extends AbstractSceneService { 27 public class SortSceneService extends AbstractSceneService {
@@ -85,31 +82,25 @@ public class SortSceneService extends AbstractSceneService { @@ -85,31 +82,25 @@ public class SortSceneService extends AbstractSceneService {
85 } 82 }
86 // 1、添加默认参数 83 // 1、添加默认参数
87 this.addParamsToParamMap(paramMap); 84 this.addParamsToParamMap(paramMap);
88 -  
89 - ConcurrentHashMap<String, String> syncParamMap = new ConcurrentHashMap<>(paramMap); 85 + CompletableFuture<SearchApiResult> productListFuture = null;
90 // 2、获取商品列表 86 // 2、获取商品列表
91 - CompletableFuture<SearchApiResult> productListFuture = CompletableFuture.supplyAsync(() -> {  
92 - try {  
93 - return sceneProductListService.productList(syncParamMap);  
94 - } catch (Exception e) {  
95 - logger.error(e.getMessage(), e);  
96 - return null;  
97 - }  
98 - }, executorService);  
99 - // 3、获取规则和自定义标签的聚合结果  
100 - CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(syncParamMap), executorService);  
101 - CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(syncParamMap), executorService);  
102 - CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(syncParamMap), executorService);  
103 - 87 + if(!"13420925".equals(this.getuid(paramMap))){
  88 + productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)),executorService);
  89 + }else{
  90 + productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)),executorService);
  91 + }
  92 + // 3、获取聚合结果
  93 + CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(this.newParamMap(paramMap)),executorService);
  94 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)),executorService);
  95 + CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(this.newParamMap(paramMap)), executorService);
104 // 4、组合结果 96 // 4、组合结果
105 SearchApiResult productList = productListFuture.get(); 97 SearchApiResult productList = productListFuture.get();
106 SearchApiResult standards = standardsFuture.get(); 98 SearchApiResult standards = standardsFuture.get();
107 - SearchApiResult customizeTags = customizeTagFuture.get(); 99 + SearchApiResult customizeTags = customizeTagFuture.get();
108 List<Object> recommendProducts = recommendProductFuture.get(); 100 List<Object> recommendProducts = recommendProductFuture.get();
109 -  
110 JSONObject jsonObject = (JSONObject) productList.getData(); 101 JSONObject jsonObject = (JSONObject) productList.getData();
111 jsonObject.put("standard", standards.getData()); 102 jsonObject.put("standard", standards.getData());
112 - jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); 103 + jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
113 jsonObject.put(RECOMMEND_PROMOTION_LIST, recommendProducts); 104 jsonObject.put(RECOMMEND_PROMOTION_LIST, recommendProducts);
114 return productList; 105 return productList;
115 } catch (Exception e) { 106 } catch (Exception e) {
@@ -135,51 +126,4 @@ public class SortSceneService extends AbstractSceneService { @@ -135,51 +126,4 @@ public class SortSceneService extends AbstractSceneService {
135 } 126 }
136 } 127 }
137 128
138 - /**  
139 - * 品类列表页针对第一页的商品,将价格高的往前面平移8个  
140 - *  
141 - * @param paramMap  
142 - * @param product_list  
143 - * @return  
144 - */  
145 - @SuppressWarnings("unused")  
146 - private List<Map<String, Object>> moveProductListSort(Map<String, String> paramMap, List<Map<String, Object>> product_list) {  
147 - // 判断页面合法性  
148 - if (!searchCommonHelper.isSortPageDefault(paramMap)) {  
149 - return product_list;  
150 - }  
151 - String page = paramMap.get("page");  
152 - if (StringUtils.isNotBlank(page) && !page.equals("1")) {  
153 - return product_list;  
154 - }  
155 - // 判断总数  
156 - int total = product_list.size();  
157 - if (total <= 10) {  
158 - return product_list;  
159 - }  
160 - // 计算均价  
161 - double totalPrice = 0;  
162 - for (Map<String, Object> product : product_list) {  
163 - totalPrice += MapUtils.getDoubleValue(product, "sales_price", 0);  
164 - }  
165 - double averagePrice = totalPrice / total;  
166 - List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();  
167 - results.add(product_list.get(0));  
168 - product_list.remove(0);  
169 - Iterator<Map<String, Object>> iterator = product_list.iterator();  
170 - int moveCount = 0;  
171 - while (iterator.hasNext() && moveCount < 8) {  
172 - Map<String, Object> product = iterator.next();  
173 - if (MapUtils.getDoubleValue(product, "sales_price", 0) >= averagePrice) {  
174 - results.add(product);  
175 - moveCount++;  
176 - iterator.remove();  
177 - }  
178 - }  
179 - if (!product_list.isEmpty()) {  
180 - results.addAll(product_list);  
181 - }  
182 - return results;  
183 - }  
184 -  
185 } 129 }
@@ -2,15 +2,29 @@ package com.yoho.search.service.scene.common; @@ -2,15 +2,29 @@ package com.yoho.search.service.scene.common;
2 2
3 import com.yoho.search.models.SearchApiResult; 3 import com.yoho.search.models.SearchApiResult;
4 import com.yoho.search.service.base.SearchRequestParams; 4 import com.yoho.search.service.base.SearchRequestParams;
  5 +
  6 +import org.apache.commons.collections.MapUtils;
5 import org.apache.commons.lang.StringUtils; 7 import org.apache.commons.lang.StringUtils;
6 8
  9 +import java.util.HashMap;
7 import java.util.Map; 10 import java.util.Map;
  11 +import java.util.concurrent.CompletableFuture;
  12 +import java.util.concurrent.Executor;
  13 +import java.util.function.Supplier;
8 14
9 public abstract class AbstractSceneService { 15 public abstract class AbstractSceneService {
10 16
11 protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; 17 protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list";
12 protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; 18 protected static final String CUSTOMIZE_TAG_LIST = "customize_tag";
13 - 19 +
  20 + protected Map<String, String> newParamMap(Map<String, String> paramMap) {
  21 + return new HashMap<String, String>(paramMap);
  22 + }
  23 +
  24 + protected CompletableFuture<?> getFuture(Supplier<?> supplier,Executor executor){
  25 + return CompletableFuture.supplyAsync(() -> supplier,executor);
  26 + }
  27 +
14 /** 28 /**
15 * 场景化的默认参数 29 * 场景化的默认参数
16 * 30 *
@@ -33,6 +47,10 @@ public abstract class AbstractSceneService { @@ -33,6 +47,10 @@ public abstract class AbstractSceneService {
33 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); 47 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
34 return page; 48 return page;
35 } 49 }
  50 +
  51 + protected String getuid(Map<String, String> paramMap) {
  52 + return MapUtils.getString(paramMap, "uid", "0");
  53 + }
36 54
37 public abstract void addParamsToParamMap(Map<String, String> paramMap); 55 public abstract void addParamsToParamMap(Map<String, String> paramMap);
38 56
@@ -5,9 +5,12 @@ import java.util.List; @@ -5,9 +5,12 @@ import java.util.List;
5 import java.util.Map; 5 import java.util.Map;
6 6
7 import org.apache.commons.lang.StringUtils; 7 import org.apache.commons.lang.StringUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
10 12
  13 +import com.alibaba.fastjson.JSONArray;
11 import com.alibaba.fastjson.JSONObject; 14 import com.alibaba.fastjson.JSONObject;
12 import com.yoho.search.base.utils.ISearchConstants; 15 import com.yoho.search.base.utils.ISearchConstants;
13 import com.yoho.search.common.cache.SearchCacheMatchLogger; 16 import com.yoho.search.common.cache.SearchCacheMatchLogger;
@@ -24,6 +27,8 @@ import com.yoho.search.service.helper.SearchSortHelper; @@ -24,6 +27,8 @@ import com.yoho.search.service.helper.SearchSortHelper;
24 @Service 27 @Service
25 public class SceneProductListService extends AbstractCacheAbleService { 28 public class SceneProductListService extends AbstractCacheAbleService {
26 29
  30 + private static final Logger logger = LoggerFactory.getLogger(SceneProductListService.class);
  31 +
27 @Autowired 32 @Autowired
28 private SearchCommonService searchCommonService; 33 private SearchCommonService searchCommonService;
29 @Autowired 34 @Autowired
@@ -47,37 +52,41 @@ public class SceneProductListService extends AbstractCacheAbleService { @@ -47,37 +52,41 @@ public class SceneProductListService extends AbstractCacheAbleService {
47 * @return 52 * @return
48 * @throws Exception 53 * @throws Exception
49 */ 54 */
50 - public SearchApiResult productList(Map<String, String> paramMap) throws Exception {  
51 - // 1)构造搜索参数  
52 - SearchParam searchParam = this.buildProductListSearchParam(paramMap); 55 + public SearchApiResult productList(Map<String, String> paramMap) {
  56 + try {
  57 + // 1)构造搜索参数
  58 + SearchParam searchParam = this.buildProductListSearchParam(paramMap);
53 59
54 - // 2)从缓存中获取数据  
55 - final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
56 - JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, searchParam);  
57 - if (cacheObject != null) {  
58 - SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/productList.json", paramMap);  
59 - return new SearchApiResult().setData(cacheObject);  
60 - } 60 + // 2)从缓存中获取数据
  61 + final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
  62 + JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, searchParam);
  63 + if (cacheObject != null) {
  64 + SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/productList.json", paramMap);
  65 + return new SearchApiResult().setData(cacheObject);
  66 + }
61 67
62 - // 3)查询ES  
63 - SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);  
64 - if (searchResult == null) {  
65 - return new SearchApiResult().setCode(500).setMessage("execption");  
66 - } 68 + // 3)查询ES
  69 + SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
  70 + if (searchResult == null) {
  71 + return new SearchApiResult().setCode(500).setMessage("execption");
  72 + }
67 73
68 - // 4)构造返回结果  
69 - JSONObject dataMap = new JSONObject();  
70 - dataMap.put("total", searchResult.getTotal());  
71 - dataMap.put("page", searchResult.getPage());  
72 - dataMap.put("page_size", searchParam.getSize());  
73 - dataMap.put("page_total", searchResult.getTotalPage());  
74 - List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());  
75 - dataMap.put("product_list", productListSortService.sortProductList(product_list, paramMap));// 处理一下商品的顺序;  
76 -  
77 - // 5)将结果存进缓存  
78 - searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);  
79 - return new SearchApiResult().setData(dataMap); 74 + // 4)构造返回结果
  75 + JSONObject dataMap = new JSONObject();
  76 + dataMap.put("total", searchResult.getTotal());
  77 + dataMap.put("page", searchResult.getPage());
  78 + dataMap.put("page_size", searchParam.getSize());
  79 + dataMap.put("page_total", searchResult.getTotalPage());
  80 + List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
  81 + dataMap.put("product_list", productListSortService.sortProductList(product_list, paramMap));// 处理一下商品的顺序;
80 82
  83 + // 5)将结果存进缓存
  84 + searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
  85 + return new SearchApiResult().setData(dataMap);
  86 + } catch (Exception e) {
  87 + logger.error(e.getMessage(), e);
  88 + return new SearchApiResult().setCode(500).setMessage("scene productList exception").setData(new JSONArray());
  89 + }
81 } 90 }
82 91
83 private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception { 92 private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
@@ -49,19 +49,25 @@ @@ -49,19 +49,25 @@
49 </mvc:interceptors> 49 </mvc:interceptors>
50 50
51 <!--字符串转换器--> 51 <!--字符串转换器-->
52 - <bean id="stringConverter"  
53 - class="org.springframework.http.converter.StringHttpMessageConverter"> 52 + <bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
54 <property name="supportedMediaTypes"> 53 <property name="supportedMediaTypes">
55 <list> 54 <list>
56 <value>text/plain;charset=UTF-8</value> 55 <value>text/plain;charset=UTF-8</value>
57 <value>text/html;charset=UTF-8</value> 56 <value>text/html;charset=UTF-8</value>
  57 + <value>application/json;charset=UTF-8</value>
58 </list> 58 </list>
59 </property> 59 </property>
60 </bean> 60 </bean>
61 61
62 <!-- json转换器 application/json --> 62 <!-- json转换器 application/json -->
63 <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> 63 <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
64 - <property name="supportedMediaTypes" value="application/json;charset=UTF-8"/> 64 + <property name="supportedMediaTypes">
  65 + <list>
  66 + <value>text/plain;charset=UTF-8</value>
  67 + <value>text/html;charset=UTF-8</value>
  68 + <value>application/json;charset=UTF-8</value>
  69 + </list>
  70 + </property>
65 <property name="features"> 71 <property name="features">
66 <array value-type="com.alibaba.fastjson.serializer.SerializerFeature"> 72 <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
67 <value>DisableCircularReferenceDetect</value> 73 <value>DisableCircularReferenceDetect</value>
@@ -148,7 +148,7 @@ @@ -148,7 +148,7 @@
148 </encoder> 148 </encoder>
149 </appender> 149 </appender>
150 150
151 - <!-- controller-cost appender --> 151 + <!-- controller-performance appender -->
152 <appender name="CONTROLLER_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender"> 152 <appender name="CONTROLLER_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
153 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 153 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
154 <fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/controller-performance.log</fileNamePattern> 154 <fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/controller-performance.log</fileNamePattern>
@@ -163,6 +163,21 @@ @@ -163,6 +163,21 @@
163 </encoder> 163 </encoder>
164 </appender> 164 </appender>
165 165
  166 + <!-- es-performance appender -->
  167 + <appender name="ES_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
  168 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  169 + <fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/es-performance.log</fileNamePattern>
  170 + <!-- 日志最大的保存天数 -->
  171 + <maxHistory>${maxHistory}</maxHistory>
  172 + </rollingPolicy>
  173 + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
  174 + <maxFileSize>${maxFileSize}</maxFileSize>
  175 + </triggeringPolicy>
  176 + <encoder>
  177 + <pattern>%-1relative - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0} -- %msg%n</pattern>
  178 + </encoder>
  179 + </appender>
  180 +
166 <!-- downgrade appender --> 181 <!-- downgrade appender -->
167 <appender name="DOWNGRADE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender"> 182 <appender name="DOWNGRADE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
168 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 183 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -268,6 +283,12 @@ @@ -268,6 +283,12 @@
268 <level value="INFO"/> 283 <level value="INFO"/>
269 <appender-ref ref="CONTROLLER_PERFORMANCE_APPENDER"/> 284 <appender-ref ref="CONTROLLER_PERFORMANCE_APPENDER"/>
270 </logger> 285 </logger>
  286 +
  287 + <!-- ES耗时统计 -->
  288 + <logger name="ES_PERFORMANCE" additivity="false">
  289 + <level value="INFO"/>
  290 + <appender-ref ref="ES_PERFORMANCE_APPENDER"/>
  291 + </logger>
271 292
272 <!-- 降级日志 --> 293 <!-- 降级日志 -->
273 <logger name="DOWNGRADE" additivity="false"> 294 <logger name="DOWNGRADE" additivity="false">
@@ -214,7 +214,7 @@ @@ -214,7 +214,7 @@
214 </encoder> 214 </encoder>
215 </appender> 215 </appender>
216 216
217 - <!-- 请求超时 appender --> 217 + <!-- controller-performance appender -->
218 <appender name="CONTROLLER_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender"> 218 <appender name="CONTROLLER_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
219 <file>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/controller-performance.log</file> 219 <file>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/controller-performance.log</file>
220 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 220 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -232,6 +232,24 @@ @@ -232,6 +232,24 @@
232 </encoder> 232 </encoder>
233 </appender> 233 </appender>
234 234
  235 + <!-- es-performance appender -->
  236 + <appender name="ES_PERFORMANCE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
  237 + <file>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/es-performance.log</file>
  238 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  239 + <!-- daily rollover -->
  240 + <fileNamePattern>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/archived/es-performance.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  241 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  242 + <!-- or whenever the file size reaches 100MB -->
  243 + <maxFileSize>${yoho.logs.maxFileSize}</maxFileSize>
  244 + </timeBasedFileNamingAndTriggeringPolicy>
  245 + <!-- keep 30 days' worth of history -->
  246 + <maxHistory>${yoho.logs.maxHistory}</maxHistory>
  247 + </rollingPolicy>
  248 + <encoder>
  249 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
  250 + </encoder>
  251 + </appender>
  252 +
235 <!-- 降级 appender --> 253 <!-- 降级 appender -->
236 <appender name="DOWNGRADE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender"> 254 <appender name="DOWNGRADE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
237 <file>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/down-grade.log</file> 255 <file>${yoho.logs.basedir}/${yoho.search.service.env.namespace}/down-grade.log</file>
@@ -342,10 +360,16 @@ @@ -342,10 +360,16 @@
342 360
343 <!-- 性能监控 --> 361 <!-- 性能监控 -->
344 <logger name="CONTROLLER_PERFORMANCE" additivity="false"> 362 <logger name="CONTROLLER_PERFORMANCE" additivity="false">
345 - <level value="INFO"/> 363 + <level value="${yoho.logs.level}"/>
346 <appender-ref ref="CONTROLLER_PERFORMANCE_APPENDER"/> 364 <appender-ref ref="CONTROLLER_PERFORMANCE_APPENDER"/>
347 </logger> 365 </logger>
348 366
  367 + <!-- ES耗时统计 -->
  368 + <logger name="ES_PERFORMANCE" additivity="false">
  369 + <level value="INFO"/>
  370 + <appender-ref ref="ES_PERFORMANCE_APPENDER"/>
  371 + </logger>
  372 +
349 <!-- 降级日志 --> 373 <!-- 降级日志 -->
350 <logger name="DOWNGRADE" additivity="false"> 374 <logger name="DOWNGRADE" additivity="false">
351 <level value="INFO"/> 375 <level value="INFO"/>
@@ -353,8 +377,8 @@ @@ -353,8 +377,8 @@
353 </logger> 377 </logger>
354 378
355 <!-- 个性化搜索日志 --> 379 <!-- 个性化搜索日志 -->
356 - <logger name="PERSONALIZED" additivity="${yoho.logs.level}">  
357 - <level value="INFO"/> 380 + <logger name="PERSONALIZED" additivity="false">
  381 + <level value="${yoho.logs.level}"/>
358 <appender-ref ref="PERSONALIZED_APPENDER"/> 382 <appender-ref ref="PERSONALIZED_APPENDER"/>
359 </logger> 383 </logger>
360 384