...
|
...
|
@@ -12,6 +12,7 @@ import com.yoho.search.service.service.SearchCommonService; |
|
|
import com.yoho.search.service.servicenew.ISuggestService;
|
|
|
import com.yoho.search.service.utils.HttpServletRequestUtils;
|
|
|
import com.yoho.search.service.utils.SearchRequestParams;
|
|
|
import com.yoho.search.service.vo.SearchApiResult;
|
|
|
import com.yoho.search.service.vo.SuggestApiResult;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
...
|
...
|
@@ -259,7 +260,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
if (StringUtils.isNotEmpty(dest)) {
|
|
|
int count = 0;
|
|
|
for (String keyword : dest.split(",")) {
|
|
|
if(!queryWord.equalsIgnoreCase(keyword)) {
|
|
|
if (!queryWord.equalsIgnoreCase(keyword)) {
|
|
|
count++;
|
|
|
resultTerms.add(keyword);
|
|
|
// 最多返回三个推荐词
|
...
|
...
|
@@ -293,6 +294,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
searchParam.setQuery(queryBuilder);
|
|
|
searchParam.setPage(1);
|
|
|
searchParam.setSize(1);
|
|
|
searchParam.setFiter(QueryBuilders.termQuery("status", 1));
|
|
|
|
|
|
// 3) 先从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_CONVERSION;
|
...
|
...
|
@@ -343,4 +345,42 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
searchParam.setFiter(QueryBuilders.rangeQuery(countField).gte(20));
|
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult suggestConversion(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
logger.info("[func=suggestConversion][param={}][begin={}]", paramMap, begin);
|
|
|
|
|
|
String queryWord = paramMap.get("query");
|
|
|
int updateTime = StringUtils.isBlank(paramMap.get("updateTime")) ? 0 : Integer.parseInt(paramMap.get("updateTime"));
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
if (page < 1) {
|
|
|
throw new IllegalArgumentException("分页参数不合法");
|
|
|
}
|
|
|
|
|
|
// 1) 构建ES请求
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
QueryBuilder queryBuilder = StringUtils.isNotEmpty(queryWord) ? QueryBuilders.matchQuery("source", queryWord) : QueryBuilders.matchAllQuery();
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
searchParam.setPage(page);
|
|
|
searchParam.setSize(1);
|
|
|
if (updateTime > 0) {
|
|
|
searchParam.setFiter(QueryBuilders.rangeQuery("updateTime").gte(updateTime));
|
|
|
}
|
|
|
|
|
|
// 2) 调用ES查询
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_CONVERSION, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 3) 返回结果
|
|
|
logger.info("[func=suggestConversion][cost={}]", System.currentTimeMillis() - begin);
|
|
|
return new SearchApiResult().setData(searchResult.getResultList());
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setCode(500).setMessage(e.getMessage()).setData(null);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|