Showing
12 changed files
with
34 additions
and
304 deletions
@@ -17,7 +17,6 @@ import org.springframework.util.Assert; | @@ -17,7 +17,6 @@ import org.springframework.util.Assert; | ||
17 | import java.util.ArrayList; | 17 | import java.util.ArrayList; |
18 | import java.util.List; | 18 | import java.util.List; |
19 | import java.util.Map; | 19 | import java.util.Map; |
20 | -import java.util.Optional; | ||
21 | import java.util.stream.Collectors; | 20 | import java.util.stream.Collectors; |
22 | 21 | ||
23 | /** | 22 | /** |
@@ -30,7 +29,6 @@ public class UfoSuggestJob implements ApplicationContextAware { | @@ -30,7 +29,6 @@ public class UfoSuggestJob implements ApplicationContextAware { | ||
30 | private static final Logger logger = LoggerFactory.getLogger("FLOW_EXECUTOR"); | 29 | private static final Logger logger = LoggerFactory.getLogger("FLOW_EXECUTOR"); |
31 | 30 | ||
32 | private List<RetryBusinessFlowExecutor> discoveryFlowExecutorList = new ArrayList<>(); | 31 | private List<RetryBusinessFlowExecutor> discoveryFlowExecutorList = new ArrayList<>(); |
33 | - //private List<RetryBusinessFlowExecutor> counterFlowExecutorList = new ArrayList<>(); | ||
34 | 32 | ||
35 | @Autowired | 33 | @Autowired |
36 | private UfoSuggestCache suggestionCache; | 34 | private UfoSuggestCache suggestionCache; |
@@ -47,20 +45,12 @@ public class UfoSuggestJob implements ApplicationContextAware { | @@ -47,20 +45,12 @@ public class UfoSuggestJob implements ApplicationContextAware { | ||
47 | .sorted((discoverer1, discoverer2) -> discoverer1.getKeywordType().compare(discoverer2.getKeywordType())) | 45 | .sorted((discoverer1, discoverer2) -> discoverer1.getKeywordType().compare(discoverer2.getKeywordType())) |
48 | .map(counter -> new RetryBusinessFlowExecutor(counter, consumerConfiger.getUfoSuggestionDiscoverBatchMaxThreadSize(), consumerConfiger.getUfoSuggestionDiscoverBatchLimit())) | 46 | .map(counter -> new RetryBusinessFlowExecutor(counter, consumerConfiger.getUfoSuggestionDiscoverBatchMaxThreadSize(), consumerConfiger.getUfoSuggestionDiscoverBatchLimit())) |
49 | .collect(Collectors.toList()); | 47 | .collect(Collectors.toList()); |
50 | - | ||
51 | -// Map<String, UfoAbstractSuggestionCounter> countBeanMap = applicationContext.getBeansOfType(UfoAbstractSuggestionCounter.class); | ||
52 | -// Assert.isTrue(countBeanMap != null && !countBeanMap.isEmpty(), "There is no ufo suggestion counter defined."); | ||
53 | -// counterFlowExecutorList = countBeanMap.values().stream() | ||
54 | -// .map(counter -> new RetryBusinessFlowExecutor(counter, consumerConfiger.getUfoSuggestionCountBatchMaxThreadSize(), consumerConfiger.getUfoSuggestionCountBatchLimit())) | ||
55 | -// .collect(Collectors.toList()); | ||
56 | } | 48 | } |
57 | 49 | ||
58 | @Scheduled(cron = "0 0 6 * * ?") | 50 | @Scheduled(cron = "0 0 6 * * ?") |
59 | public void executeAll() { | 51 | public void executeAll() { |
60 | executeDiscovery(); | 52 | executeDiscovery(); |
61 | safeSleep(); | 53 | safeSleep(); |
62 | - //executeCounter(); | ||
63 | - //safeSleep(); | ||
64 | indexRebuildJob.rebuildUfoSuggestIndex(); | 54 | indexRebuildJob.rebuildUfoSuggestIndex(); |
65 | } | 55 | } |
66 | 56 | ||
@@ -85,42 +75,6 @@ public class UfoSuggestJob implements ApplicationContextAware { | @@ -85,42 +75,6 @@ public class UfoSuggestJob implements ApplicationContextAware { | ||
85 | } | 75 | } |
86 | } | 76 | } |
87 | 77 | ||
88 | -// private void executeCounter() { | ||
89 | -// long begin = System.currentTimeMillis(); | ||
90 | -// logger.info("UfoSuggestionJob executeCounter start [begin={}]", begin); | ||
91 | -// boolean result = true; | ||
92 | -// for (RetryBusinessFlowExecutor executor : counterFlowExecutorList) { | ||
93 | -// boolean tempResult = executor.execute(); | ||
94 | -// if (!tempResult) { | ||
95 | -// logger.warn("UfoSuggestionJob executeCounter has failure [bean={}]", executor.getFlowName()); | ||
96 | -// } | ||
97 | -// result = result && tempResult; | ||
98 | -// } | ||
99 | -// logger.info("SuggestionJob.executeCounter end [cost={}][result={}]", (System.currentTimeMillis() - begin), result); | ||
100 | -// } | ||
101 | - | ||
102 | - | ||
103 | - public void executeDiscoveryForSingleFlow(String flowName) { | ||
104 | - try { | ||
105 | - long begin = System.currentTimeMillis(); | ||
106 | - logger.info("SuggestionJob.executeDiscoveryForSingleFlow start----[begin={}]", begin); | ||
107 | - suggestionCache.init(); | ||
108 | - Optional<RetryBusinessFlowExecutor> executor = discoveryFlowExecutorList.stream().filter(item -> flowName.equals(item.getFlowName())).findAny(); | ||
109 | - executor.ifPresent(RetryBusinessFlowExecutor::execute); | ||
110 | - logger.info("SuggestionJob.executeDiscoveryForSingleFlow end----[cost={}]", (System.currentTimeMillis() - begin)); | ||
111 | - } finally { | ||
112 | - suggestionCache.cleanup(); | ||
113 | - } | ||
114 | - } | ||
115 | - | ||
116 | -// public void executeCounterForSingleFlow(String flowName) { | ||
117 | -// long begin = System.currentTimeMillis(); | ||
118 | -// logger.info("SuggestionJob.executeCounter start----[begin={}]", begin); | ||
119 | -// Optional<RetryBusinessFlowExecutor> executor = counterFlowExecutorList.stream().filter(item -> flowName.equals(item.getFlowName())).findAny(); | ||
120 | -// executor.ifPresent(RetryBusinessFlowExecutor::execute); | ||
121 | -// logger.info("SuggestionJob.executeCounter end----[cost={}]", (System.currentTimeMillis() - begin)); | ||
122 | -// } | ||
123 | - | ||
124 | private void safeSleep() { | 78 | private void safeSleep() { |
125 | try { | 79 | try { |
126 | Thread.sleep(10000L); | 80 | Thread.sleep(10000L); |
@@ -16,7 +16,7 @@ import java.util.concurrent.ConcurrentHashMap; | @@ -16,7 +16,7 @@ import java.util.concurrent.ConcurrentHashMap; | ||
16 | 16 | ||
17 | /** | 17 | /** |
18 | * @author wangnan | 18 | * @author wangnan |
19 | - * @Version 2019/6/4 | 19 | + * @version 2019/6/4 |
20 | */ | 20 | */ |
21 | @Component | 21 | @Component |
22 | public class UfoSuggestCache { | 22 | public class UfoSuggestCache { |
@@ -59,7 +59,7 @@ public class UfoSuggestCache { | @@ -59,7 +59,7 @@ public class UfoSuggestCache { | ||
59 | return oldValue == null; | 59 | return oldValue == null; |
60 | } | 60 | } |
61 | 61 | ||
62 | - public String generateIdentifier(String keyword) { | 62 | + private String generateIdentifier(String keyword) { |
63 | if (StringUtils.isEmpty(keyword)) { | 63 | if (StringUtils.isEmpty(keyword)) { |
64 | return "empty"; | 64 | return "empty"; |
65 | } | 65 | } |
@@ -21,7 +21,7 @@ import java.util.List; | @@ -21,7 +21,7 @@ import java.util.List; | ||
21 | public class UfoSuggestSearchParamBuilder { | 21 | public class UfoSuggestSearchParamBuilder { |
22 | 22 | ||
23 | @Autowired | 23 | @Autowired |
24 | - private ConsumerConfiger configer; | 24 | + private ConsumerConfiger config; |
25 | 25 | ||
26 | public SearchParam build(String keyword) { | 26 | public SearchParam build(String keyword) { |
27 | SearchParam searchParam = new SearchParam(); | 27 | SearchParam searchParam = new SearchParam(); |
@@ -36,15 +36,15 @@ public class UfoSuggestSearchParamBuilder { | @@ -36,15 +36,15 @@ public class UfoSuggestSearchParamBuilder { | ||
36 | boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0)); | 36 | boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0)); |
37 | boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1)); | 37 | boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1)); |
38 | // 对男女关键字做特殊处理 | 38 | // 对男女关键字做特殊处理 |
39 | - boolean cotainBoy = keyword.contains("男"); | ||
40 | - boolean cotainGirl = keyword.contains("女"); | 39 | + boolean containBoy = keyword.contains("男"); |
40 | + boolean containGirl = keyword.contains("女"); | ||
41 | // 对性别做特殊处理 | 41 | // 对性别做特殊处理 |
42 | String gender = null; | 42 | String gender = null; |
43 | - if (cotainBoy && !cotainGirl) { | 43 | + if (containBoy && !containGirl) { |
44 | gender = "1,3"; | 44 | gender = "1,3"; |
45 | - } else if (!cotainBoy && cotainGirl) { | 45 | + } else if (!containBoy && containGirl) { |
46 | gender = "2,3"; | 46 | gender = "2,3"; |
47 | - } else if (cotainBoy && cotainGirl) { | 47 | + } else if (containBoy && containGirl) { |
48 | gender = "1,2,3"; | 48 | gender = "1,2,3"; |
49 | } | 49 | } |
50 | if (gender != null) { | 50 | if (gender != null) { |
@@ -65,9 +65,9 @@ public class UfoSuggestSearchParamBuilder { | @@ -65,9 +65,9 @@ public class UfoSuggestSearchParamBuilder { | ||
65 | queryBuilder.type(multiMatchQueryBuilderType); | 65 | queryBuilder.type(multiMatchQueryBuilderType); |
66 | } | 66 | } |
67 | setDefaultSearchField(queryBuilder); | 67 | setDefaultSearchField(queryBuilder); |
68 | - if (configer.getSearchOperator().equalsIgnoreCase("or")) { | 68 | + if (config.getSearchOperator().equalsIgnoreCase("or")) { |
69 | queryBuilder.operator(Operator.OR); | 69 | queryBuilder.operator(Operator.OR); |
70 | - queryBuilder.minimumShouldMatch(configer.getSearchMinimumShouldMatch()); | 70 | + queryBuilder.minimumShouldMatch(config.getSearchMinimumShouldMatch()); |
71 | } else { | 71 | } else { |
72 | queryBuilder.operator(Operator.AND); | 72 | queryBuilder.operator(Operator.AND); |
73 | } | 73 | } |
@@ -75,7 +75,7 @@ public class UfoSuggestSearchParamBuilder { | @@ -75,7 +75,7 @@ public class UfoSuggestSearchParamBuilder { | ||
75 | } | 75 | } |
76 | 76 | ||
77 | private MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() { | 77 | private MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() { |
78 | - String configMultiMatchQueryType = configer.getSearchMultiMatchQueryType(); | 78 | + String configMultiMatchQueryType = config.getSearchMultiMatchQueryType(); |
79 | return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType); | 79 | return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType); |
80 | } | 80 | } |
81 | 81 |
@@ -26,7 +26,7 @@ public class UfoSuggestSplitUtils { | @@ -26,7 +26,7 @@ public class UfoSuggestSplitUtils { | ||
26 | return results; | 26 | return results; |
27 | } | 27 | } |
28 | 28 | ||
29 | - public static Set<String> splitProductName(String token) { | 29 | + private static Set<String> splitProductName(String token) { |
30 | Set<String> results = new HashSet<String>(); | 30 | Set<String> results = new HashSet<String>(); |
31 | if (StringUtils.isBlank(token)) { | 31 | if (StringUtils.isBlank(token)) { |
32 | return results; | 32 | return results; |
@@ -13,25 +13,23 @@ import java.util.stream.Stream; | @@ -13,25 +13,23 @@ import java.util.stream.Stream; | ||
13 | public class UfoSuggestionConstants { | 13 | public class UfoSuggestionConstants { |
14 | public static final Integer VALID_STATUS = 1; | 14 | public static final Integer VALID_STATUS = 1; |
15 | 15 | ||
16 | - public static final Set<String> IGNORE_KEYWORDS = Stream.of("") | ||
17 | - .map(String::toLowerCase).collect(Collectors.toSet()); | ||
18 | - | 16 | + public static final Set<String> IGNORE_KEYWORDS = Stream.of("").map(String::toLowerCase).collect(Collectors.toSet()); |
19 | public static final List<String> IGNORE_BRAND_NAMES = Arrays.asList(""); | 17 | public static final List<String> IGNORE_BRAND_NAMES = Arrays.asList(""); |
20 | 18 | ||
21 | - public static final int SMART_SUGGESTION_TERM_COUNT = 10; | ||
22 | - public static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | 19 | + public static String UFO_SERIES_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.series.name.enable"; |
20 | + public static String UFO_BRAND_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brand.name.enable"; | ||
21 | + public static String UFO_SORT_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.sort.name.enable"; | ||
22 | + | ||
23 | + public static String UFO_PRODUCT_NAME_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.product.name.token.enable"; | ||
24 | + public static String UFO_PRODUCT_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.product.keyword.token.enable"; | ||
25 | + public static String UFO_BRAND_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.brand.keyword.token.enable"; | ||
26 | + public static String UFO_SERIES_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.series.keyword.token.enable"; | ||
27 | + | ||
28 | + public static String UFO_BRAND_AND_SORT_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brand.and.sort.name.enable"; | ||
29 | + public static String UFO_BRAND_AND_SERIES_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brand.and.series.name.enable"; | ||
23 | 30 | ||
24 | - public static String UFO_BRAND_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brandname.enable"; | ||
25 | - public static String UFO_SORT_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.sortname.enable"; | ||
26 | - public static String UFO_BRAND_AND_SORT_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brandwithsortname.enable"; | ||
27 | - public static String UFO_BRAND_AND_SERIES_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.brandwithseriesname.enable"; | ||
28 | 31 | ||
29 | - public static String UFO_PRODUCT_NAME_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.productname.token.enable"; | ||
30 | - public static String UFO_PRODUCT_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.productkeyword.token.enable"; | ||
31 | - public static String UFO_BRAND_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.brandkeyword.token.enable"; | ||
32 | - public static String UFO_SERIES_KEYWORD_TOKEN_ENABLED_KEY = "ufo.search.suggestion.consumer.brandkeyword.token.enable"; | ||
33 | 32 | ||
34 | - public static String UFO_SERIES_NAME_ENABLED_KEY = "ufo.search.suggestion.consumer.seriesname.enable"; | ||
35 | 33 | ||
36 | 34 | ||
37 | } | 35 | } |
1 | -package com.yoho.search.consumer.ufosuggests.counter; | ||
2 | - | ||
3 | -import com.yoho.search.consumer.index.rebuild.RebuildFlagService; | ||
4 | -import com.yoho.search.consumer.suggests.common.RetryBusinessFlow; | ||
5 | -import com.yoho.search.consumer.suggests.counter.CountUsage; | ||
6 | -import com.yoho.search.consumer.suggests.counter.KeywordCounterService; | ||
7 | -import org.slf4j.Logger; | ||
8 | -import org.slf4j.LoggerFactory; | ||
9 | -import org.springframework.beans.factory.annotation.Autowired; | ||
10 | -import org.springframework.context.ApplicationEventPublisher; | ||
11 | -import org.springframework.context.ApplicationEventPublisherAware; | ||
12 | - | ||
13 | -import java.util.Map; | ||
14 | -import java.util.stream.Collectors; | ||
15 | - | ||
16 | -/** | ||
17 | - * 建议词计数器 抽象类 | ||
18 | - * @author wangnan | ||
19 | - * @version 2019/6/4 | ||
20 | - */ | ||
21 | -public abstract class UfoAbstractSuggestionCounter implements ApplicationEventPublisherAware, RetryBusinessFlow { | ||
22 | - | ||
23 | - protected static final Logger logger = LoggerFactory.getLogger("FLOW_EXECUTOR"); | ||
24 | - | ||
25 | - @Autowired | ||
26 | - private KeywordCounterService keywordCounterService; | ||
27 | - | ||
28 | - @Autowired | ||
29 | - private RebuildFlagService rebuildFlagService; | ||
30 | - | ||
31 | - protected ApplicationEventPublisher publisher; | ||
32 | - | ||
33 | - @Override | ||
34 | - public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { | ||
35 | - this.publisher = applicationEventPublisher; | ||
36 | - } | ||
37 | - | ||
38 | - @Override | ||
39 | - public String flowName() { | ||
40 | - return this.getClass().getSimpleName(); | ||
41 | - } | ||
42 | - | ||
43 | - @Override | ||
44 | - public void init() { | ||
45 | - rebuildFlagService.waitingRebuildingIndex(); | ||
46 | - rebuildFlagService.updateIsBuildingTrue(); | ||
47 | - } | ||
48 | - | ||
49 | - @Override | ||
50 | - public boolean doBusiness(int pageNo, int batchSize) { | ||
51 | - Map<String, Object> keywordMap = getKeywordMap(pageNo, batchSize); | ||
52 | - int fetchSize = keywordMap != null ? keywordMap.size() : 0; | ||
53 | - if (fetchSize == 0) { | ||
54 | - logger.info("[{} business][pageNo={}][fetchWordSize={}]", flowName(), pageNo, fetchSize); | ||
55 | - return true; | ||
56 | - } | ||
57 | - | ||
58 | - Map<String, Integer> countMapForApp = keywordCounterService.batchCount(keywordMap.keySet().stream().collect(Collectors.toList()), CountUsage.APP); | ||
59 | - int countMapSizeForApp = countMapForApp != null ? countMapForApp.size() : 0; | ||
60 | - if (countMapSizeForApp == 0) { | ||
61 | - logger.info("[{} business][pageNo={}][countMapSizeForApp={}]", flowName(), pageNo, countMapSizeForApp); | ||
62 | - return false; | ||
63 | - } | ||
64 | - | ||
65 | - Map<String, Integer> countMapForPC = keywordCounterService.batchCount(keywordMap.keySet().stream().collect(Collectors.toList()), CountUsage.PC); | ||
66 | - int countMapSizeForPC = countMapForPC != null ? countMapForPC.size() : 0; | ||
67 | - if (countMapSizeForPC == 0) { | ||
68 | - logger.info("[{} business][pageNo={}][countMapForPC={}]", flowName(), pageNo, countMapSizeForPC); | ||
69 | - return false; | ||
70 | - } | ||
71 | - | ||
72 | - Map<String, Integer> countMapForBlk = keywordCounterService.batchCount(keywordMap.keySet().stream().collect(Collectors.toList()), CountUsage.BLK); | ||
73 | - int countMapSizeForBlk = countMapForBlk != null ? countMapForBlk.size() : 0; | ||
74 | - if (countMapSizeForBlk == 0) { | ||
75 | - logger.info("[{} business][pageNo={}][countMapSizeForBlk={}]", flowName(), pageNo, countMapSizeForBlk); | ||
76 | - return false; | ||
77 | - } | ||
78 | - | ||
79 | - logger.info("[{} business][pageNo={}][fetchWordSize={}][countMapSizeForApp={}][countMapSizeForPC={}][countMapSizeForBlk={}]", | ||
80 | - flowName(), pageNo, fetchSize, countMapSizeForApp, countMapSizeForPC, countMapSizeForBlk); | ||
81 | - return persistence(keywordMap, countMapForApp, countMapForPC, countMapForBlk); | ||
82 | - } | ||
83 | - | ||
84 | - protected Integer calCount(Map<String, Integer> countResultMap, String suggestWord) { | ||
85 | - Integer count = countResultMap.get(suggestWord); | ||
86 | - return count != null ? count : Integer.valueOf(0); | ||
87 | - } | ||
88 | - | ||
89 | - @Override | ||
90 | - public void finish(boolean doBusinessResult, Exception exception) { | ||
91 | - rebuildFlagService.updateIsBuildingFalse(); | ||
92 | - } | ||
93 | - | ||
94 | - abstract Map<String, Object> getKeywordMap(int pageNo, int batchSize); | ||
95 | - | ||
96 | - abstract boolean persistence(Map<String, Object> keywordMap, Map<String, Integer> countMapForApp, Map<String, Integer> countMapForPC, Map<String, Integer> countMapForBlk); | ||
97 | -} |
1 | -package com.yoho.search.consumer.ufosuggests.counter; | ||
2 | - | ||
3 | -import com.yoho.search.base.utils.ISearchConstants; | ||
4 | -import com.yoho.search.consumer.common.IYohoIndexService; | ||
5 | -import com.yoho.search.consumer.suggests.common.SuggestSearchParamBuilder; | ||
6 | -import com.yoho.search.consumer.suggests.counter.CountUsage; | ||
7 | -import com.yoho.search.core.es.model.SearchParam; | ||
8 | -import com.yoho.search.core.es.model.SearchResult; | ||
9 | -import com.yoho.search.dal.model.SuggestWordDef; | ||
10 | -import org.springframework.beans.factory.annotation.Autowired; | ||
11 | -import org.springframework.stereotype.Component; | ||
12 | -import org.springframework.util.Assert; | ||
13 | - | ||
14 | -import java.util.ArrayList; | ||
15 | -import java.util.LinkedHashMap; | ||
16 | -import java.util.List; | ||
17 | -import java.util.Map; | ||
18 | -import java.util.stream.Collectors; | ||
19 | - | ||
20 | -/** | ||
21 | - * 关键词计数器 | ||
22 | - * @author wangnan | ||
23 | - * @version 2019/6/4 | ||
24 | - */ | ||
25 | -@Component | ||
26 | -public class UfoKeywordCounterService { | ||
27 | - @Autowired | ||
28 | - private IYohoIndexService yohoIndexService; | ||
29 | - @Autowired | ||
30 | - private SuggestSearchParamBuilder suggestSearchParamBuilder; | ||
31 | - | ||
32 | - public Map<String, Integer> batchCount(List<String> keywords, CountUsage countUsage) { | ||
33 | - Assert.notNull(keywords); | ||
34 | - Map<String, Integer> countResultMap = new LinkedHashMap<>(); | ||
35 | - List<SearchParam> searchParams = keywords.stream().map(keyword -> suggestSearchParamBuilder.build(keyword, countUsage)).collect(Collectors.toList()); | ||
36 | - List<SearchResult> results = yohoIndexService.multiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); | ||
37 | - Assert.notNull(results); | ||
38 | - Assert.isTrue(results.size() == keywords.size()); | ||
39 | - for (int i = 0; i < keywords.size(); i++) { | ||
40 | - countResultMap.put(keywords.get(i), Integer.valueOf(String.valueOf(results.get(i).getTotal()))); | ||
41 | - } | ||
42 | - | ||
43 | - return countResultMap; | ||
44 | - } | ||
45 | - | ||
46 | - public SuggestWordDef countKeyword(String keyword) { | ||
47 | - Assert.notNull(keyword); | ||
48 | - List<SearchParam> searchParams = new ArrayList<>(); | ||
49 | - searchParams.add(suggestSearchParamBuilder.build(keyword, CountUsage.PC)); | ||
50 | - searchParams.add(suggestSearchParamBuilder.build(keyword, CountUsage.APP)); | ||
51 | - searchParams.add(suggestSearchParamBuilder.build(keyword, CountUsage.BLK)); | ||
52 | - List<SearchResult> results = yohoIndexService.multiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); | ||
53 | - Assert.notNull(results); | ||
54 | - Assert.isTrue(results.size() == 3); | ||
55 | - | ||
56 | - SuggestWordDef suggestWordDef = new SuggestWordDef(); | ||
57 | - suggestWordDef.setKeyword(keyword); | ||
58 | - suggestWordDef.setCount(Integer.valueOf(String.valueOf(results.get(0).getTotal()))); | ||
59 | - suggestWordDef.setCountForApp(Integer.valueOf(String.valueOf(results.get(1).getTotal()))); | ||
60 | - suggestWordDef.setCountForBlk(Integer.valueOf(String.valueOf(results.get(2).getTotal()))); | ||
61 | - return suggestWordDef; | ||
62 | - } | ||
63 | -} |
index/src/main/java/com/yoho/search/consumer/ufosuggests/counter/UfoSuggestWordCounter.java
deleted
100644 → 0
1 | -package com.yoho.search.consumer.ufosuggests.counter; | ||
2 | - | ||
3 | -import com.yoho.search.consumer.common.ConsumerDynamicConfigService; | ||
4 | -import com.yoho.search.consumer.service.daoService.ufo.UfoSuggestWordService; | ||
5 | -import com.yoho.search.consumer.suggests.common.KeywordType; | ||
6 | -import com.yoho.search.consumer.suggests.common.SuggestionConstants; | ||
7 | -import com.yoho.search.consumer.ufosuggests.common.UfoKeywordType; | ||
8 | -import com.yoho.search.dal.model.UfoSuggestWord; | ||
9 | -import org.apache.commons.collections.CollectionUtils; | ||
10 | -import org.springframework.beans.factory.annotation.Autowired; | ||
11 | -import org.springframework.stereotype.Component; | ||
12 | - | ||
13 | -import java.util.*; | ||
14 | -import java.util.stream.Collectors; | ||
15 | -import java.util.stream.Stream; | ||
16 | - | ||
17 | -/** | ||
18 | - * 建议词计数器 | ||
19 | - * @author wangnan | ||
20 | - * @version 2019/6/5 | ||
21 | - */ | ||
22 | -@Component | ||
23 | -public class UfoSuggestWordCounter extends UfoAbstractSuggestionCounter { | ||
24 | - @Autowired | ||
25 | - private UfoSuggestWordService suggestWordService; | ||
26 | - @Autowired | ||
27 | - private ConsumerDynamicConfigService consumerDynamicConfigService; | ||
28 | - | ||
29 | - @Override | ||
30 | - public int getTotalCount() { | ||
31 | - return suggestWordService.selectTotalCount(); | ||
32 | - } | ||
33 | - | ||
34 | - @Override | ||
35 | - Map<String, Object> getKeywordMap(int pageNo, int batchSize) { | ||
36 | - int start = (pageNo - 1) * batchSize; | ||
37 | - Map<String, Object> wordMap = new HashMap<>(batchSize); | ||
38 | - List<UfoSuggestWord> dataList = suggestWordService.selectPageList(start, batchSize); | ||
39 | - if (CollectionUtils.isNotEmpty(dataList)) { | ||
40 | - Set<Integer> enabledKeywordTypes = Stream.of(UfoKeywordType.values()).filter(keywordType -> consumerDynamicConfigService.ufoSuggestKeywordTypeOpen(keywordType)) | ||
41 | - .map(UfoKeywordType::getType).collect(Collectors.toSet()); | ||
42 | - dataList.stream().filter(item -> SuggestionConstants.VALID_STATUS.equals(item.getStatus())).filter(item -> enabledKeywordTypes.contains(item.getType())) | ||
43 | - .forEach(item -> wordMap.put(item.getKeyword(), item)); | ||
44 | - } | ||
45 | - return wordMap; | ||
46 | - } | ||
47 | - | ||
48 | - @Override | ||
49 | - boolean persistence(Map<String, Object> keywordMap, Map<String, Integer> countMapForApp, Map<String, Integer> countMapForPC, Map<String, Integer> countMapForBlk) { | ||
50 | - List<UfoSuggestWord> batchList = new ArrayList<>(countMapForApp.size()); | ||
51 | - countMapForApp.forEach((keyword, count) -> { | ||
52 | - UfoSuggestWord ufoSuggestWord = (UfoSuggestWord) keywordMap.get(keyword); | ||
53 | - if (ufoSuggestWord != null) { | ||
54 | - ufoSuggestWord.setCount(calCount(countMapForPC, keyword)); | ||
55 | - ufoSuggestWord.setWeight(KeywordType.getWeightValueByType(ufoSuggestWord.getType())); | ||
56 | - batchList.add(ufoSuggestWord); | ||
57 | - } | ||
58 | - }); | ||
59 | - suggestWordService.updateBatch(batchList); | ||
60 | - return true; | ||
61 | - } | ||
62 | -} |
@@ -7,7 +7,7 @@ import com.yoho.search.core.es.agg.IAggregation; | @@ -7,7 +7,7 @@ import com.yoho.search.core.es.agg.IAggregation; | ||
7 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | - * 商品关键词词条发现器 | 10 | + * 商品名称词条发现器 |
11 | * @author wangnan | 11 | * @author wangnan |
12 | * @version 2019/6/4 | 12 | * @version 2019/6/4 |
13 | */ | 13 | */ |
@@ -53,16 +53,8 @@ public class ConsumerConfiger { | @@ -53,16 +53,8 @@ public class ConsumerConfiger { | ||
53 | } | 53 | } |
54 | 54 | ||
55 | /******************************for UFO Suggestion**************************************/ | 55 | /******************************for UFO Suggestion**************************************/ |
56 | - public int getUfoSuggestionCountBatchLimit (){ | ||
57 | - return configurer.getInt("ufo.suggestion.count.batch.limit", 300); | ||
58 | - } | ||
59 | - | ||
60 | - public int getUfoSuggestionCountBatchMaxThreadSize(){ | ||
61 | - return configurer.getInt("ufo.suggestion.count.batch.max.thread.size", 1); | ||
62 | - } | ||
63 | - | ||
64 | public int getUfoSuggestionDiscoverBatchLimit(){ | 56 | public int getUfoSuggestionDiscoverBatchLimit(){ |
65 | - return configurer.getInt("ufo.suggestion.discover.batch.limit", 500); | 57 | + return configurer.getInt("ufo.suggestion.discover.batch.limit", 300); |
66 | } | 58 | } |
67 | 59 | ||
68 | public int getUfoSuggestionDiscoverBatchMaxThreadSize(){ | 60 | public int getUfoSuggestionDiscoverBatchMaxThreadSize(){ |
@@ -38,5 +38,9 @@ suggestion.discover.batch.max.thread.size=3 | @@ -38,5 +38,9 @@ suggestion.discover.batch.max.thread.size=3 | ||
38 | suggestion.count.agg.size=10000 | 38 | suggestion.count.agg.size=10000 |
39 | suggestion.count.agg.mindoc=5 | 39 | suggestion.count.agg.mindoc=5 |
40 | 40 | ||
41 | +#ufo suggestion | ||
42 | +ufo.suggestion.discover.batch.limit=500 | ||
43 | +ufo.suggestion.discover.batch.max.thread.size=3 | ||
44 | + | ||
41 | #not log profile.threshold | 45 | #not log profile.threshold |
42 | profile.threshold=10000000 | 46 | profile.threshold=10000000 |
@@ -38,5 +38,9 @@ suggestion.discover.batch.max.thread.size=${suggestion.discover.batch.max.thread | @@ -38,5 +38,9 @@ suggestion.discover.batch.max.thread.size=${suggestion.discover.batch.max.thread | ||
38 | suggestion.count.agg.size=${suggestion.count.agg.size} | 38 | suggestion.count.agg.size=${suggestion.count.agg.size} |
39 | suggestion.count.agg.mindoc=${suggestion.count.agg.mindoc} | 39 | suggestion.count.agg.mindoc=${suggestion.count.agg.mindoc} |
40 | 40 | ||
41 | +#ufo suggestion | ||
42 | +ufo.suggestion.discover.batch.limit=${ufo.suggestion.discover.batch.limit} | ||
43 | +ufo.suggestion.discover.batch.max.thread.size=${ufo.suggestion.discover.batch.max.thread.size} | ||
44 | + | ||
41 | #not log profile.threshold | 45 | #not log profile.threshold |
42 | profile.threshold=10000000 | 46 | profile.threshold=10000000 |
-
Please register or login to post a comment