suggestTips异常时也返回默认的提示词
Showing
1 changed file
with
22 additions
and
32 deletions
1 | package com.yoho.search.service.servicenew.impl; | 1 | package com.yoho.search.service.servicenew.impl; |
2 | 2 | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.Arrays; | ||
5 | -import java.util.HashMap; | ||
6 | -import java.util.List; | ||
7 | -import java.util.Map; | ||
8 | -import java.util.Set; | ||
9 | -import java.util.stream.Collectors; | ||
10 | - | ||
11 | -import org.apache.commons.collections.CollectionUtils; | ||
12 | -import org.apache.commons.lang.StringUtils; | ||
13 | -import org.elasticsearch.common.lucene.search.function.CombineFunction; | ||
14 | -import org.elasticsearch.index.query.BoolQueryBuilder; | ||
15 | -import org.elasticsearch.index.query.MatchQueryBuilder; | ||
16 | -import org.elasticsearch.index.query.MultiMatchQueryBuilder; | ||
17 | -import org.elasticsearch.index.query.QueryBuilder; | ||
18 | -import org.elasticsearch.index.query.QueryBuilders; | ||
19 | -import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; | ||
20 | -import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; | ||
21 | -import org.elasticsearch.search.sort.SortBuilder; | ||
22 | -import org.elasticsearch.search.sort.SortBuilders; | ||
23 | -import org.elasticsearch.search.sort.SortOrder; | ||
24 | -import org.elasticsearch.search.suggest.SuggestBuilders; | ||
25 | -import org.elasticsearch.search.suggest.term.TermSuggestion; | ||
26 | -import org.slf4j.Logger; | ||
27 | -import org.slf4j.LoggerFactory; | ||
28 | -import org.springframework.beans.factory.annotation.Autowired; | ||
29 | -import org.springframework.context.ApplicationEventPublisher; | ||
30 | -import org.springframework.context.ApplicationEventPublisherAware; | ||
31 | -import org.springframework.stereotype.Service; | ||
32 | - | ||
33 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
34 | import com.yoho.error.event.SearchEvent; | 4 | import com.yoho.error.event.SearchEvent; |
35 | import com.yoho.search.base.utils.CharUtils; | 5 | import com.yoho.search.base.utils.CharUtils; |
@@ -47,6 +17,26 @@ import com.yoho.search.service.utils.HttpServletRequestUtils; | @@ -47,6 +17,26 @@ import com.yoho.search.service.utils.HttpServletRequestUtils; | ||
47 | import com.yoho.search.service.utils.SearchRequestParams; | 17 | import com.yoho.search.service.utils.SearchRequestParams; |
48 | import com.yoho.search.service.vo.SearchApiResult; | 18 | import com.yoho.search.service.vo.SearchApiResult; |
49 | import com.yoho.search.service.vo.SuggestApiResult; | 19 | import com.yoho.search.service.vo.SuggestApiResult; |
20 | +import org.apache.commons.collections.CollectionUtils; | ||
21 | +import org.apache.commons.lang.StringUtils; | ||
22 | +import org.elasticsearch.common.lucene.search.function.CombineFunction; | ||
23 | +import org.elasticsearch.index.query.*; | ||
24 | +import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; | ||
25 | +import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; | ||
26 | +import org.elasticsearch.search.sort.SortBuilder; | ||
27 | +import org.elasticsearch.search.sort.SortBuilders; | ||
28 | +import org.elasticsearch.search.sort.SortOrder; | ||
29 | +import org.elasticsearch.search.suggest.SuggestBuilders; | ||
30 | +import org.elasticsearch.search.suggest.term.TermSuggestion; | ||
31 | +import org.slf4j.Logger; | ||
32 | +import org.slf4j.LoggerFactory; | ||
33 | +import org.springframework.beans.factory.annotation.Autowired; | ||
34 | +import org.springframework.context.ApplicationEventPublisher; | ||
35 | +import org.springframework.context.ApplicationEventPublisherAware; | ||
36 | +import org.springframework.stereotype.Service; | ||
37 | + | ||
38 | +import java.util.*; | ||
39 | +import java.util.stream.Collectors; | ||
50 | 40 | ||
51 | @Service | 41 | @Service |
52 | public class SuggestServiceImpl implements ISuggestService, ApplicationEventPublisherAware { | 42 | public class SuggestServiceImpl implements ISuggestService, ApplicationEventPublisherAware { |
@@ -257,7 +247,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl | @@ -257,7 +247,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl | ||
257 | JSONObject suggestTipResult = suggestTipsBySuggestIndex(paramMap); | 247 | JSONObject suggestTipResult = suggestTipsBySuggestIndex(paramMap); |
258 | if (suggestTipResult == null) { | 248 | if (suggestTipResult == null) { |
259 | // 2.1) 可能是ES发生异常 如果搜索不到相关是应该是集合为空而不是对象为null | 249 | // 2.1) 可能是ES发生异常 如果搜索不到相关是应该是集合为空而不是对象为null |
260 | - return null; | 250 | + return defaultSuggestTips(); |
261 | } | 251 | } |
262 | 252 | ||
263 | List<String> resultTerms = (List<String>) suggestTipResult.get("terms_suggestion"); | 253 | List<String> resultTerms = (List<String>) suggestTipResult.get("terms_suggestion"); |
@@ -275,7 +265,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl | @@ -275,7 +265,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl | ||
275 | return defaultSuggestTips(); | 265 | return defaultSuggestTips(); |
276 | } catch (Exception e) { | 266 | } catch (Exception e) { |
277 | logger.error("[func=suggestTips]Get suggestion by keyword [" + queryWord + "] failed!", e); | 267 | logger.error("[func=suggestTips]Get suggestion by keyword [" + queryWord + "] failed!", e); |
278 | - return null; | 268 | + return defaultSuggestTips(); |
279 | } | 269 | } |
280 | } | 270 | } |
281 | 271 |
-
Please register or login to post a comment