Showing
4 changed files
with
93 additions
and
25 deletions
@@ -35,6 +35,7 @@ public class SuggestExtendedIndexBuilder extends IIndexBuilder { | @@ -35,6 +35,7 @@ public class SuggestExtendedIndexBuilder extends IIndexBuilder { | ||
35 | Set<Integer> enabledKeywordTypes = Stream.of(KeywordType.values()).filter(keywordType -> dynamicConfigService.suggestKeywordTypeOpen(keywordType)) | 35 | Set<Integer> enabledKeywordTypes = Stream.of(KeywordType.values()).filter(keywordType -> dynamicConfigService.suggestKeywordTypeOpen(keywordType)) |
36 | .map(KeywordType::getType).collect(Collectors.toSet()); | 36 | .map(KeywordType::getType).collect(Collectors.toSet()); |
37 | List<SuggestWordDef> list = suggestWordDefService.selectPageList(offset, limit); | 37 | List<SuggestWordDef> list = suggestWordDefService.selectPageList(offset, limit); |
38 | + // 根据Type取权重 | ||
38 | for (SuggestWordDef suggestWordDef : list) { | 39 | for (SuggestWordDef suggestWordDef : list) { |
39 | suggestWordDef.setWeight(KeywordType.getWeightValueByType(suggestWordDef.getType())); | 40 | suggestWordDef.setWeight(KeywordType.getWeightValueByType(suggestWordDef.getType())); |
40 | } | 41 | } |
1 | package com.yoho.search.consumer.index.fullbuild; | 1 | package com.yoho.search.consumer.index.fullbuild; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.stereotype.Component; | ||
8 | + | ||
3 | import com.yoho.search.base.utils.MD5Util; | 9 | import com.yoho.search.base.utils.MD5Util; |
4 | import com.yoho.search.consumer.index.common.IIndexBuilder; | 10 | import com.yoho.search.consumer.index.common.IIndexBuilder; |
5 | import com.yoho.search.consumer.service.base.SuggestionKeywordsService; | 11 | import com.yoho.search.consumer.service.base.SuggestionKeywordsService; |
12 | +import com.yoho.search.consumer.service.bo.SuggestIndexBO; | ||
6 | import com.yoho.search.dal.model.SuggestionKeywords; | 13 | import com.yoho.search.dal.model.SuggestionKeywords; |
7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
8 | -import org.springframework.stereotype.Component; | ||
9 | - | ||
10 | -import java.util.List; | ||
11 | -import java.util.stream.Collectors; | ||
12 | 14 | ||
13 | @Component | 15 | @Component |
14 | public class SuggestIndexBuilder extends IIndexBuilder { | 16 | public class SuggestIndexBuilder extends IIndexBuilder { |
15 | 17 | ||
16 | - @Autowired | ||
17 | - private SuggestionKeywordsService suggestionKeywordsService; | ||
18 | - | ||
19 | - @Override | ||
20 | - public int getTotalCount() throws Exception { | ||
21 | - return suggestionKeywordsService.count(); | ||
22 | - } | ||
23 | - | ||
24 | - @Override | ||
25 | - public List<?> getPageLists(int offset, int limit) throws Exception { | ||
26 | - List<SuggestionKeywords> list = suggestionKeywordsService.getPageLists(offset, limit); | ||
27 | - //老的建议词的权重设为0【最低】 | ||
28 | - for (SuggestionKeywords suggestionKeyword : list) { | ||
29 | - suggestionKeyword.setWeight(0); | 18 | + @Autowired |
19 | + private SuggestionKeywordsService suggestionKeywordsService; | ||
20 | + | ||
21 | + @Override | ||
22 | + public int getTotalCount() throws Exception { | ||
23 | + return suggestionKeywordsService.count(); | ||
24 | + } | ||
25 | + | ||
26 | + @Override | ||
27 | + public List<?> getPageLists(int offset, int limit) throws Exception { | ||
28 | + List<SuggestionKeywords> guggestionKeywordList = suggestionKeywordsService.getPageLists(offset, limit); | ||
29 | + List<SuggestIndexBO> results = new ArrayList<SuggestIndexBO>(); | ||
30 | + for (SuggestionKeywords kw : guggestionKeywordList) { | ||
31 | + if (kw.getCount() == null || kw.getCount() == 0) { | ||
32 | + continue; | ||
33 | + } | ||
34 | + int type = -1; | ||
35 | + int weight = -1; | ||
36 | + results.add(new SuggestIndexBO(kw.getKeyword(), type, weight, kw.getCount())); | ||
30 | } | 37 | } |
31 | - return list.stream().filter(item -> item.getCount() != null && item.getCount() > 0).collect(Collectors.toList()); | ||
32 | - } | 38 | + return results; |
39 | + } | ||
33 | 40 | ||
34 | - @Override | ||
35 | - public String getId(Object object) { | ||
36 | - return MD5Util.string2MD5(((SuggestionKeywords) object).getKeyword().trim().toLowerCase()); | ||
37 | - } | 41 | + @Override |
42 | + public String getId(Object object) { | ||
43 | + return MD5Util.string2MD5(((SuggestIndexBO) object).getKeyword().trim().toLowerCase()); | ||
44 | + } | ||
38 | 45 | ||
39 | } | 46 | } |
@@ -26,6 +26,13 @@ | @@ -26,6 +26,13 @@ | ||
26 | }, | 26 | }, |
27 | "type": "multi_field" | 27 | "type": "multi_field" |
28 | }, | 28 | }, |
29 | + "type": { | ||
30 | + "type": "long", | ||
31 | + "doc_values": true, | ||
32 | + "fielddata": { | ||
33 | + "format": "doc_values" | ||
34 | + } | ||
35 | + }, | ||
29 | "weight": { | 36 | "weight": { |
30 | "type": "long", | 37 | "type": "long", |
31 | "doc_values": true, | 38 | "doc_values": true, |
1 | +package com.yoho.search.consumer.service.bo; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +public class SuggestIndexBO implements Serializable { | ||
6 | + | ||
7 | + private static final long serialVersionUID = 7154651415633074270L; | ||
8 | + private String keyword; | ||
9 | + private int type; | ||
10 | + private int weight; | ||
11 | + private int count; | ||
12 | + | ||
13 | + public SuggestIndexBO(String keyword, int type, int weight, int count) { | ||
14 | + super(); | ||
15 | + this.keyword = keyword; | ||
16 | + this.type = type; | ||
17 | + this.weight = weight; | ||
18 | + this.count = count; | ||
19 | + } | ||
20 | + | ||
21 | + public String getKeyword() { | ||
22 | + return keyword; | ||
23 | + } | ||
24 | + | ||
25 | + public void setKeyword(String keyword) { | ||
26 | + this.keyword = keyword; | ||
27 | + } | ||
28 | + | ||
29 | + public int getType() { | ||
30 | + return type; | ||
31 | + } | ||
32 | + | ||
33 | + public void setType(int type) { | ||
34 | + this.type = type; | ||
35 | + } | ||
36 | + | ||
37 | + public int getWeight() { | ||
38 | + return weight; | ||
39 | + } | ||
40 | + | ||
41 | + public void setWeight(int weight) { | ||
42 | + this.weight = weight; | ||
43 | + } | ||
44 | + | ||
45 | + public int getCount() { | ||
46 | + return count; | ||
47 | + } | ||
48 | + | ||
49 | + public void setCount(int count) { | ||
50 | + this.count = count; | ||
51 | + } | ||
52 | + | ||
53 | +} |
-
Please register or login to post a comment