Authored by 胡古飞

修改重建建议词索引的逻辑

package com.yoho.search.consumer.index.fullbuild;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
... ... @@ -12,10 +13,10 @@ import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.consumer.common.DynamicConfigService;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.base.SuggestWordDefService;
import com.yoho.search.consumer.service.bo.SuggestIndexBO;
import com.yoho.search.consumer.suggests.common.KeywordType;
import com.yoho.search.consumer.suggests.common.SuggestionConstants;
import com.yoho.search.dal.model.SuggestWordDef;
import com.yoho.search.dal.model.SuggestionKeywords;
@Component
public class SuggestExtendedIndexBuilder extends IIndexBuilder {
... ... @@ -34,19 +35,27 @@ public class SuggestExtendedIndexBuilder extends IIndexBuilder {
public List<?> getPageLists(int offset, int limit) throws Exception {
Set<Integer> enabledKeywordTypes = Stream.of(KeywordType.values()).filter(keywordType -> dynamicConfigService.suggestKeywordTypeOpen(keywordType))
.map(KeywordType::getType).collect(Collectors.toSet());
// 获取分页列表
List<SuggestWordDef> list = suggestWordDefService.selectPageList(offset, limit);
// 根据Type取权重
// 构建结果
List<SuggestIndexBO> results = new ArrayList<SuggestIndexBO>();
for (SuggestWordDef suggestWordDef : list) {
suggestWordDef.setWeight(KeywordType.getWeightValueByType(suggestWordDef.getType()));
if (suggestWordDef.getCount() == null || suggestWordDef.getCount() == 0) {
continue;
}
if (!suggestWordDef.getStatus().equals(SuggestionConstants.VALID_STATUS) || !enabledKeywordTypes.contains(suggestWordDef.getType())) {
continue;
}
// 根据Type取权重
int weight = KeywordType.getWeightValueByType(suggestWordDef.getType());
results.add(new SuggestIndexBO(suggestWordDef.getKeyword(), suggestWordDef.getType(), weight, suggestWordDef.getCount()));
}
return list.stream().filter(item -> item.getCount() != null && item.getCount() > 0).filter(item -> SuggestionConstants.VALID_STATUS.equals(item.getStatus()))
.filter(item -> enabledKeywordTypes.contains(item.getType())).map(item -> new SuggestionKeywords(item.getKeyword(), item.getCount(), item.getCount()))
.collect(Collectors.toList());
return results;
}
@Override
public String getId(Object object) {
return MD5Util.string2MD5(((SuggestionKeywords) object).getKeyword().trim().toLowerCase());
return MD5Util.string2MD5(((SuggestIndexBO) object).getKeyword().trim().toLowerCase());
}
}
... ...