Authored by 胡古飞

根据类型设置权重

... ... @@ -35,6 +35,7 @@ public class SuggestExtendedIndexBuilder extends IIndexBuilder {
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取权重
for (SuggestWordDef suggestWordDef : list) {
suggestWordDef.setWeight(KeywordType.getWeightValueByType(suggestWordDef.getType()));
}
... ...
package com.yoho.search.consumer.index.fullbuild;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.base.SuggestionKeywordsService;
import com.yoho.search.consumer.service.bo.SuggestIndexBO;
import com.yoho.search.dal.model.SuggestionKeywords;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class SuggestIndexBuilder extends IIndexBuilder {
... ... @@ -23,17 +25,22 @@ public class SuggestIndexBuilder extends IIndexBuilder {
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
List<SuggestionKeywords> list = suggestionKeywordsService.getPageLists(offset, limit);
//老的建议词的权重设为0【最低】
for (SuggestionKeywords suggestionKeyword : list) {
suggestionKeyword.setWeight(0);
List<SuggestionKeywords> guggestionKeywordList = suggestionKeywordsService.getPageLists(offset, limit);
List<SuggestIndexBO> results = new ArrayList<SuggestIndexBO>();
for (SuggestionKeywords kw : guggestionKeywordList) {
if (kw.getCount() == null || kw.getCount() == 0) {
continue;
}
int type = -1;
int weight = -1;
results.add(new SuggestIndexBO(kw.getKeyword(), type, weight, kw.getCount()));
}
return list.stream().filter(item -> item.getCount() != null && item.getCount() > 0).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());
}
}
... ...
... ... @@ -26,6 +26,13 @@
},
"type": "multi_field"
},
"type": {
"type": "long",
"doc_values": true,
"fielddata": {
"format": "doc_values"
}
},
"weight": {
"type": "long",
"doc_values": true,
... ...
package com.yoho.search.consumer.service.bo;
import java.io.Serializable;
public class SuggestIndexBO implements Serializable {
private static final long serialVersionUID = 7154651415633074270L;
private String keyword;
private int type;
private int weight;
private int count;
public SuggestIndexBO(String keyword, int type, int weight, int count) {
super();
this.keyword = keyword;
this.type = type;
this.weight = weight;
this.count = count;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
... ...