...
|
...
|
@@ -6,15 +6,12 @@ import com.yoho.search.consumer.service.base.SuggestWordDefService; |
|
|
import com.yoho.search.consumer.suggests.common.KeywordType;
|
|
|
import com.yoho.search.consumer.suggests.common.RetryBusinessFlow;
|
|
|
import com.yoho.search.consumer.suggests.common.SuggestionCache;
|
|
|
import com.yoho.search.consumer.suggests.common.SuggestionConstants;
|
|
|
import com.yoho.search.dal.model.SuggestWordDef;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
...
|
...
|
@@ -48,38 +45,38 @@ public abstract class AbstractSuggestionDiscoverer implements RetryBusinessFlow |
|
|
rebuildFlagService.updateIsBuildingTrue();
|
|
|
|
|
|
// 删除suggest_word_def表的原始数据
|
|
|
Integer type = getKeywordType().getType();
|
|
|
int countByType = suggestWordDefService.selectCountByWordType(type);
|
|
|
if (countByType == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
final int limit = SuggestionConstants.SUGGESTION_DISCOVER_BATCH_LIMIT;
|
|
|
final int totalPageSize = (countByType - 1) / limit + 1;
|
|
|
logger.info("[{} init][countByType={}][totalPageSize={}]", flowName(), countByType, totalPageSize);
|
|
|
List<Integer> toDeletedIdList = new ArrayList<>();
|
|
|
for (int pageNo = 1; pageNo <= totalPageSize; pageNo++) {
|
|
|
final int start = (pageNo - 1) * limit;
|
|
|
List<SuggestWordDef> wordDefList = suggestWordDefService.selectByKeywordType(type, start, limit);
|
|
|
Map<Boolean, List<SuggestWordDef>> partitionList = wordDefList.stream().collect(Collectors.partitioningBy(word -> SuggestionConstants.VALID_STATUS.equals(word.getStatus())));
|
|
|
logger.info("[{} init][pageNo={}][validCount={}][invalidCount={}]", flowName(), pageNo, partitionList.get(Boolean.TRUE).size(), partitionList.get(Boolean.FALSE).size());
|
|
|
partitionList.get(Boolean.FALSE).stream().map(SuggestWordDef::getKeyword).forEach((keyword) -> suggestionCache.add(keyword));
|
|
|
toDeletedIdList.addAll(partitionList.get(Boolean.TRUE).stream().map(SuggestWordDef::getId).collect(Collectors.toList()));
|
|
|
}
|
|
|
|
|
|
int fromIndex = 0;
|
|
|
while (fromIndex < toDeletedIdList.size()) {
|
|
|
int endIndex = fromIndex + limit;
|
|
|
if (endIndex > toDeletedIdList.size()) {
|
|
|
endIndex = toDeletedIdList.size();
|
|
|
}
|
|
|
|
|
|
List<Integer> subIdList = toDeletedIdList.subList(fromIndex, endIndex);
|
|
|
logger.info("[{} init][deleteBatchSize={}]", flowName(), subIdList.size());
|
|
|
logger.trace("[{} init][deleteBatch={}]", flowName(), subIdList);
|
|
|
suggestWordDefService.deleteBatch(subIdList);
|
|
|
fromIndex += limit;
|
|
|
}
|
|
|
// Integer type = getKeywordType().getType();
|
|
|
// int countByType = suggestWordDefService.selectCountByWordType(type);
|
|
|
// if (countByType == 0) {
|
|
|
// return;
|
|
|
// }
|
|
|
//
|
|
|
// final int limit = SuggestionConstants.SUGGESTION_DISCOVER_BATCH_LIMIT;
|
|
|
// final int totalPageSize = (countByType - 1) / limit + 1;
|
|
|
// logger.info("[{} init][countByType={}][totalPageSize={}]", flowName(), countByType, totalPageSize);
|
|
|
// List<Integer> toDeletedIdList = new ArrayList<>();
|
|
|
// for (int pageNo = 1; pageNo <= totalPageSize; pageNo++) {
|
|
|
// final int start = (pageNo - 1) * limit;
|
|
|
// List<SuggestWordDef> wordDefList = suggestWordDefService.selectByKeywordType(type, start, limit);
|
|
|
// Map<Boolean, List<SuggestWordDef>> partitionList = wordDefList.stream().collect(Collectors.partitioningBy(word -> SuggestionConstants.VALID_STATUS.equals(word.getStatus())));
|
|
|
// logger.info("[{} init][pageNo={}][validCount={}][invalidCount={}]", flowName(), pageNo, partitionList.get(Boolean.TRUE).size(), partitionList.get(Boolean.FALSE).size());
|
|
|
// partitionList.get(Boolean.FALSE).stream().map(SuggestWordDef::getKeyword).forEach((keyword) -> suggestionCache.add(keyword));
|
|
|
// toDeletedIdList.addAll(partitionList.get(Boolean.TRUE).stream().map(SuggestWordDef::getId).collect(Collectors.toList()));
|
|
|
// }
|
|
|
//
|
|
|
// int fromIndex = 0;
|
|
|
// while (fromIndex < toDeletedIdList.size()) {
|
|
|
// int endIndex = fromIndex + limit;
|
|
|
// if (endIndex > toDeletedIdList.size()) {
|
|
|
// endIndex = toDeletedIdList.size();
|
|
|
// }
|
|
|
//
|
|
|
// List<Integer> subIdList = toDeletedIdList.subList(fromIndex, endIndex);
|
|
|
// logger.info("[{} init][deleteBatchSize={}]", flowName(), subIdList.size());
|
|
|
// logger.trace("[{} init][deleteBatch={}]", flowName(), subIdList);
|
|
|
// suggestWordDefService.deleteBatch(subIdList);
|
|
|
// fromIndex += limit;
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
|