|
|
package com.yoho.search.consumer.index.fullbuild;
|
|
|
|
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@Component
|
|
|
public class SuggestIndexBuilderByConversation extends IIndexBuilder {
|
|
|
|
|
|
@Autowired
|
|
|
private SuggestWordDefService suggestWordDefService;
|
|
|
|
|
|
@Autowired
|
|
|
private DynamicConfigService dynamicConfigService;
|
|
|
|
|
|
@Override
|
|
|
public int getTotalCount() throws Exception {
|
|
|
return suggestWordDefService.selectTotalCount();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
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);
|
|
|
// 构建结果
|
|
|
List<SuggestIndexBO> results = new ArrayList<SuggestIndexBO>();
|
|
|
for (SuggestWordDef suggestWordDef : list) {
|
|
|
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(), suggestWordDef.getCountForApp(), suggestWordDef.getCountForBlk()));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getId(Object object) {
|
|
|
return MD5Util.string2MD5(((SuggestIndexBO) object).getKeyword().trim().toLowerCase());
|
|
|
}
|
|
|
|
|
|
} |