IndexRebuildJob.java
8.59 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.yoho.search.consumer.job;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.common.IYohoIndexService;
import com.yoho.search.consumer.index.rebuild.RebuildFlagService;
import com.yoho.search.consumer.service.daoService.ProductPriceService;
import com.yoho.search.consumer.service.logicService.SknFlowLogLogicService;
import com.yoho.search.consumer.service.utils.BrandRelationUtils;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class IndexRebuildJob implements ApplicationEventPublisherAware {
private final Logger logger = LoggerFactory.getLogger(getClass());
private ApplicationEventPublisher publisher;
@Autowired
private IYohoIndexService yohoIndexService;
@Autowired
private RebuildFlagService rebuildFlagService;
@Autowired
private ProductPriceService productPriceService;
@Autowired
private SknFlowLogLogicService sknFlowLogLogicService;
@Autowired
private BrandRelationUtils brandRelationUtils;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
@Scheduled(cron = "0 0 4 * * ?")
public void rebuildIndexTask() {
productPriceService.batchUpdateHistoryPrice();
sknFlowLogLogicService.processSknFlowLog();
executeYohoIndex();
executeYohoBigdataIndex();
executeUfoIndex();
}
/**
* 业务相关的索引
*/
public void executeYohoIndex() {
long begin = System.currentTimeMillis();
brandRelationUtils.buildBrandRelation();
logger.info("executeYohoIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PROMOTIONINDEX);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SIZE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_COLOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_SORT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_STYLE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_STANDARD);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_ROBOTQUESTION);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_ROBOTQUESTION_OLD);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_PRICE_PLAN);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_HELPER);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SHOPS);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_ZQ_NAME);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PROMOTIONTYPE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_IMAGE_REPERTORY);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_COMMON);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_PRODUCT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_SORT_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_SORT_PRICE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SKN_FLOW);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CUSTOMIZE_TAG);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SHOPSBRANDS);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_COLLAGE_ACTIVITY);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_COLLAGE_PRODUCT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CUT_PRICE_CONFIG);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CUTDOWN_PRICE_ACTIVITY);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CUTDOWN_PRICE_PRODUCT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_SEARCH_LABLE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SALES_CATEGORY_SEARCH_LABLE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CS_SEARCH_RESOURCE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_POOL);
//重建pi
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PRODUCT_INDEX);
logger.info("executeYohoIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
//重建全球购
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_TBL_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_TBLPRODUCT_NEW);
}
/**
* 重建ufo所有索引
*/
public void executeUfoIndex() {
long begin = System.currentTimeMillis();
logger.info("executeUfoIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SORT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_COLOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SIZE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX);
logger.info("executeUfoIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
}
/**
* 大数据相关的索引
*/
public void executeYohoBigdataIndex() {
long begin = System.currentTimeMillis();
logger.info("executeYohoBigdataIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_YOHO_PRODUCT_ANALYSIS);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_IMAGE_VECTORS);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_SIMILAR_SKN_INDEX);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR_W2V);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR_W2V);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BIGDATA_SKN_IMAGE_VECTOR_INDEX);
logger.info("executeYohoBigdataIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
}
/**
* suggest索引由于需要依赖productindex索引计算关键词的count 由SuggestionJob触发执行
*/
public void rebuildSuggestIndex() {
long begin = System.currentTimeMillis();
logger.info("indexRebuildJob rebuildSuggestIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SUGGEST);
logger.info("indexRebuildJob rebuildSuggestIndex end----[cost={}]", System.currentTimeMillis() - begin);
}
/**
* conversion索引由于需要suggest索引的重建 由SpiderJob触发执行
*/
public void rebuildConversionIndex() {
long begin = System.currentTimeMillis();
logger.info("indexRebuildJob rebuildConversionIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_CONVERSION);
logger.info("indexRebuildJob rebuildConversionIndex end----[cost={}]", System.currentTimeMillis() - begin);
}
private void rebuildIndexWithlog(String indexName) {
try {
long begin = System.currentTimeMillis();
logger.info("rebuild index start----[indexName={}][begin={}]", indexName, begin);
rebuildFlagService.waitingRebuildingIndex();
yohoIndexService.rebuild(indexName);
logger.info("rebuild index end----[indexName={}][end={}][cost={}ms]", indexName, System.currentTimeMillis(), (System.currentTimeMillis() - begin));
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.INDEXREBUILDJOB_REBUILDINDEXWITHLOG.getEventName(), EventReportEnum.INDEXREBUILDJOB_REBUILDINDEXWITHLOG
.getFunctionName(), EventReportEnum.INDEXREBUILDJOB_REBUILDINDEXWITHLOG.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
logger.error(e.getMessage(), e);
}
}
}