Authored by 胡古飞

Merge branch 'zf_agg' into gray

... ... @@ -3,6 +3,7 @@ package com.yoho.search.service.aggregations.impls;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.service.aggregations.AggInterface;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.servicenew.IShopsService;
import com.yoho.search.service.servicenew.impl.SearchAfterCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -17,6 +18,9 @@ public class AggregationFactoryService {
@Autowired
private SearchAfterCacheService searchAfterCacheService;
@Autowired
private IShopsService shopsService;
public IAggregation getSubAggregationByType(int type, Map<String, String> paramMap) {
IAggregation iAggregation = null;
switch (type) {
... ... @@ -127,4 +131,11 @@ public class AggregationFactoryService {
return new SortGroupAggregation(paramMap);
}
public IAggregation getKeywordAggregation(int aggCount) {
return new KeywordAggregation(aggCount);
}
public IAggregation getShopAggregation(int aggCount) {
return new ShopAggregation(shopsService, aggCount);
}
}
... ...
package com.yoho.search.service.aggregations.impls;
import org.apache.commons.collections.CollectionUtils;
import org.elasticsearch.search.aggregations.Aggregation;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class KeywordAggregation extends AbstractSingleFieldAggregation {
private static final List<String> IGNORE_KEYWORDS = Arrays.asList("正常", "无", "中", "中国");
public KeywordAggregation(int count) {
super(count);
}
@Override
public String aggName() {
return "keywordAgg";
}
@Override
protected String getField() {
return "productAttrField";
}
@Override
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
List<String> valueList = (List<String>)super.getAggregationResponseMap(aggMaps);
if(CollectionUtils.isNotEmpty(valueList)){
valueList.removeAll(IGNORE_KEYWORDS);
}
return valueList;
}
}
... ...
package com.yoho.search.service.aggregations.impls;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.service.servicenew.IShopsService;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
import org.apache.commons.collections.CollectionUtils;
import org.elasticsearch.search.aggregations.Aggregation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ShopAggregation extends AbstractSingleFieldAggregation {
private IShopsService shopsService;
public ShopAggregation(IShopsService shopsService, int count) {
super(count);
this.shopsService = shopsService;
}
@Override
public String aggName() {
return "shopAgg";
}
@Override
protected String getField() {
return "shopId";
}
@Override
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
List<String> shopIdList = (List<String>) super.getAggregationResponseMap(aggMaps);
if (CollectionUtils.isNotEmpty(shopIdList)) {
shopIdList = shopIdList.stream().map(Integer::valueOf).filter(shopId -> shopId != null && shopId.intValue() > 0).map(String::valueOf).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(shopIdList)) {
return new ArrayList<>();
}
// 调用Shops索引查询确保shopId有效
Map<String, String> shopsParam = new HashMap<>();
shopsParam.put(SearchRequestParams.PARAM_SEARCH_SHOP, shopIdList.stream().collect(Collectors.joining(",")));
shopsParam.put(SearchRequestParams.SHOPS_PARAM_STATUS, "1");
SearchApiResult searchApiResult = shopsService.getShopsInfo(shopsParam);
if (searchApiResult == null || searchApiResult.getData() == null || searchApiResult.getCode() != 200) {
return new ArrayList<>();
}
JSONObject jsonObject = (JSONObject) searchApiResult.getData();
Map<String, Map<String, Object>> shopsInfo = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo");
return shopsInfo == null || shopsInfo.isEmpty() ? new ArrayList<>() : shopsInfo.values().stream().collect(Collectors.toList());
}
}
... ...
... ... @@ -175,4 +175,32 @@ public class ProductIndexController implements ApplicationEventPublisherAware {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggSpecialoffer(paramMap);
}
/**
* 从商品列表聚合关键词,随机返回关键词
*
* @param request
* @return
*/
@DownGradeAble(key = "recommendKeyword")
@RequestMapping(method = RequestMethod.GET, value = "/recommendKeyword")
@ResponseBody
public SearchApiResult recommendKeyword(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggKeywords(paramMap);
}
/**
* 聚合关键词
*
* @param request
* @return
*/
@DownGradeAble(key = "recommendShop")
@RequestMapping(method = RequestMethod.GET, value = "/recommendShop")
@ResponseBody
public SearchApiResult recommendShop(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productIndexService.aggShops(paramMap);
}
}
... ...
... ... @@ -40,22 +40,21 @@ public class ToolsController {
/**
* 获取热搜词结果
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/hotSearchWords")
@ResponseBody
public SearchApiResult hotSearchWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getHotkeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
Map<String, Object> results = searchKeyWordService.getHotkeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
... ... @@ -70,15 +69,15 @@ public class ToolsController {
@ResponseBody
public SearchApiResult emptyResultKeywords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getEmptyKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
Map<String, Object> results = searchKeyWordService.getEmptyKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
... ... @@ -87,22 +86,44 @@ public class ToolsController {
/**
* 获取一页搜索词
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/lessKeyWords")
@ResponseBody
public SearchApiResult lessKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "true") boolean returnTodayRecords) {
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getLessKeyWords(limit, onlyShowKeyWord ? false : returnTodayRecords);
Map<String, Object> results = searchKeyWordService.getLessKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("-1")) {
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
}
/**
* 获取需要推荐的关键词
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/recomKeyWords")
@ResponseBody
public SearchApiResult recomKeyWords(@RequestParam(defaultValue = "1000") int limit,
@RequestParam(defaultValue = "false") boolean onlyShowKeyWord,
@RequestParam(defaultValue = "") String dateStr) {
SearchApiResult searchApiResult = new SearchApiResult();
Map<String, Object> results = searchKeyWordService.getNeedRecomKeyWords(limit, dateStr);
if (!onlyShowKeyWord) {
return searchApiResult.setData(results);
}
List<String> keywords = new ArrayList<>();
for (KeyWordWithCount keyWordWithCount : (List<KeyWordWithCount>) results.get("keywords")) {
keywords.add(keyWordWithCount.getKeyWord());
}
return searchApiResult.setData(keywords);
... ... @@ -124,7 +145,6 @@ public class ToolsController {
/**
* 获取分词结果
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/analyzeTokens")
... ... @@ -138,7 +158,6 @@ public class ToolsController {
/**
* 清除本地缓存
*
* @param request 请求
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/clearLocalCache")
... ...
package com.yoho.search.service.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.utils.SearchRequestParams;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
... ... @@ -17,17 +23,10 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.utils.SearchRequestParams;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Service
public class AggregationService implements ApplicationEventPublisherAware {
... ... @@ -324,4 +323,29 @@ public class AggregationService implements ApplicationEventPublisherAware {
return this.getAggNameAndResponse(isSecialofferAggregation, searchParam, paramMap, filterParamName);
}
/**
* 获取商品关键词的聚合,来源与风格、款式和属性。
*
* @param searchParam
* @param paramMap
* @return
* @throws Exception
*/
public JSONObject getKeywordAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
IAggregation keywordAggregation = aggregationFactoryService.getKeywordAggregation(aggCount);
return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
}
/**
* 获取商品关键词的聚合,来源与风格、款式和属性。
*
* @param searchParam
* @param paramMap
* @return
* @throws Exception
*/
public JSONObject getShopAggregationResult(SearchParam searchParam, Map<String, String> paramMap, int aggCount) throws Exception {
IAggregation keywordAggregation = aggregationFactoryService.getShopAggregation(aggCount);
return this.getAggNameAndResponse(keywordAggregation, searchParam, paramMap, null);
}
}
... ...
... ... @@ -22,7 +22,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
... ... @@ -40,8 +39,6 @@ public class SearchKeyWordService {
private static final Logger logger = LoggerFactory.getLogger(SearchKeyWordService.class);
private static final Logger EMPTY_RESULT = LoggerFactory.getLogger("EMPTY_RESULT");
@Resource(name = "yhNoSyncZSetOperations")
private YHZSetOperations<String, String> yhNoSyncZSetOperations;
... ... @@ -118,10 +115,6 @@ public class SearchKeyWordService {
}
}
public void recordSuggestTip(String queryWord) {
recordKeyWord(RedisKeys.YOHO_SEARCH_KEYWORDS_TIPS, queryWord);
}
// 异步的做法是防止redis报错影响搜索主流程
private void recordKeyWord(String redisKeyTemplate, String queryWord) {
service.submit(new Runnable() {
... ... @@ -183,79 +176,61 @@ public class SearchKeyWordService {
}
}
public Double getKeywordCount(String redisKeyTemplate, String queryWord){
public void recordSuggestRecom(String queryWord) {
recordKeyWord(RedisKeys.YOHO_SEARCH_KEYWORDS_TIPS, queryWord);
}
public Double getKeywordCount(String redisKeyTemplate, String queryWord) {
try {
return yhNoSyncZSetOperations.score(RedisKeys.getRedisKey4Yesterday(redisKeyTemplate), queryWord);
}catch (Exception e){
} catch (Exception e) {
return null;
}
}
// 获取【热搜】toplist
public Map<String, Object> getHotkeyWords(int limit, boolean isReturnTodayRecords) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_HOT, limit, isReturnTodayRecords);
public Map<String, Object> getHotkeyWords(int limit, String dateStr) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_HOT, limit, dateStr);
}
// 获取空结果的toplist
public Map<String, Object> getEmptyKeyWords(int limit, boolean isReturnTodayRecords) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_EMPTY, limit, isReturnTodayRecords);
public Map<String, Object> getEmptyKeyWords(int limit, String dateStr) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_EMPTY, limit, dateStr);
}
// 获取只有一页结果的toplist
public Map<String, Object> getLessKeyWords(int limit, boolean isReturnTodayRecords) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_LESS, limit, isReturnTodayRecords);
public Map<String, Object> getLessKeyWords(int limit, String dateStr) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_LESS, limit, dateStr);
}
// 获取需要搜索推荐的关键词
public Map<String, Object> getNeedRecomKeyWords(int limit, String dateStr) {
return this.getListByScoreDesc(RedisKeys.YOHO_SEARCH_KEYWORDS_TIPS, limit, dateStr);
}
private Map<String, Object> getListByScoreDesc(String redisKeyTemplate, int limit, boolean isReturnTodayRecords) {
private Map<String, Object> getListByScoreDesc(String redisKeyTemplate, int limit, String dateStr) {
Map<String, Object> resultMap = new HashMap<>(3);
resultMap.put("dateForRedisKey", dateForRedisKey);
if (this.dateForRedisKey == null) {
return resultMap;
String date = dateStr;
if (StringUtils.isEmpty(date)) {
date = this.dateForRedisKey;
}
if (StringUtils.isEmpty(date)) {
date = DateUtil.DateToString(new Date(), DateStyle.YYYYMMDD);
}
String redisKey = RedisKeys.getRedisKey4Yesterday(redisKeyTemplate);
String redisKey = String.format(redisKeyTemplate, date);
Set<ZSetOperations.TypedTuple<String>> redisResults = yhNoSyncZSetOperations.reverseRangeWithScores(redisKey, 0, limit);
List<KeyWordWithCount> results = new ArrayList<KeyWordWithCount>();
for (TypedTuple<String> typedTuple : redisResults) {
results.add(new KeyWordWithCount(typedTuple.getValue(), (int) typedTuple.getScore().doubleValue()));
}
if (isReturnTodayRecords) {
// 也返回今天的数据
String redisKey4Today = RedisKeys.getRedisKey4Today(redisKeyTemplate);
Set<ZSetOperations.TypedTuple<String>> redisResults4Today = yhNoSyncZSetOperations.reverseRangeWithScores(redisKey4Today, 0, limit);
List<KeyWordWithCount> results4Today = new ArrayList<KeyWordWithCount>();
for (TypedTuple<String> typedTuple : redisResults4Today) {
results4Today.add(new KeyWordWithCount(typedTuple.getValue(), (int) typedTuple.getScore().doubleValue()));
}
resultMap.put("0", results4Today);
}
resultMap.put("redisKey", redisKey);
resultMap.put("-1", results);
resultMap.put("keywords", results);
return resultMap;
}
public void handleEmptyRecords(Map<String, String> paramMap) {
StringBuilder paramStringBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
paramStringBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
String paramString = paramStringBuilder.toString().replaceFirst("&", "");
EMPTY_RESULT.info("empty records for search.json: time[{}], param [{}]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()), paramString);
// 商品池或品类列表 为空,则告警
if (paramMap.get("filter_poolId") != null) {// ||
// paramMap.get("msort")!=null
// ||
// paramMap.get("misort")!=null
// ||
// paramMap.get("sort")!=null
// /TODO
}
}
public String deleteRedisKey(String redisKey) {
if (yhNoSyncRedisTemplate.hasKey(redisKey)) {
yhNoSyncRedisTemplate.delete(redisKey);
... ...
package com.yoho.search.service.servicenew;
import java.util.Map;
import com.yoho.search.service.vo.SearchApiResult;
import java.util.Map;
public interface IProductIndexService {
/**
... ... @@ -83,4 +83,13 @@ public interface IProductIndexService {
* @return
*/
public SearchApiResult aggSpecialoffer(Map<String, String> paramMap);
/**
* 商品关键词的聚合,来源与风格、款式和属性。
* @param paramMap
* @return
*/
SearchApiResult aggKeywords(Map<String, String> paramMap);
SearchApiResult aggShops(Map<String, String> paramMap);
}
... ...
... ... @@ -29,4 +29,6 @@ public interface IShopsService {
* @return
*/
public SearchApiResult searchShopsNew(Map<String, String> paramMap);
SearchApiResult getShopsInfo(Map<String, String> paramMap);
}
... ...
package com.yoho.search.service.servicenew.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.JsonUtil;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.service.AggregationService;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.servicenew.IProductIndexService;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.service.vo.SearchApiResult;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -21,9 +20,11 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.core.es.model.SearchParam;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
@Service
public class ProductIndexServiceImpl implements IProductIndexService,ApplicationEventPublisherAware {
... ... @@ -245,4 +246,45 @@ public class ProductIndexServiceImpl implements IProductIndexService,Application
}
});
}
@Override
public SearchApiResult aggKeywords(Map<String, String> paramMap) {
final int randomKeywordCount = StringUtils.isBlank(paramMap.get("keyword_count")) ? 8 : Integer.parseInt(paramMap.get("keyword_count"));
return this.getSearchApiResult("aggKeywords", paramMap, new Searcher() {
@Override
public Object getResult() throws Exception {
SearchParam searchParam = getSearchParamFromMap(paramMap);
JSONObject jsonObject = aggregationService.getKeywordAggregationResult(searchParam, paramMap, 50);
List<String> keywordList = (List<String>) jsonObject.get("keywordAgg");
return getRandomKeywords(keywordList, randomKeywordCount);
}
});
}
private List<String> getRandomKeywords(List<String> keywordList, int randomKeywordCount) {
if (keywordList == null || keywordList.size() <= randomKeywordCount) {
return keywordList;
}
return new Random().ints(0, keywordList.size())
.distinct()
.limit(randomKeywordCount)
.mapToObj(index -> keywordList.get(index))
.collect(Collectors.toList());
}
@Override
public SearchApiResult aggShops(Map<String, String> paramMap) {
final int page = StringUtils.isBlank(paramMap.get("shop_page")) ? 1 : Integer.parseInt(paramMap.get("shop_page"));
final int count = StringUtils.isBlank(paramMap.get("shop_count")) ? 1 : Integer.parseInt(paramMap.get("shop_count"));
return this.getSearchApiResult("aggShops", paramMap, new Searcher() {
@Override
public Object getResult() throws Exception {
SearchParam searchParam = getSearchParamFromMap(paramMap);
JSONObject jsonObject = aggregationService.getShopAggregationResult(searchParam, paramMap, 30);
List<Map<String, Object>> shopList = (List<Map<String, Object>>) jsonObject.get("shopAgg");
return CollectionUtils.memoryPaging(shopList, page, count);
}
});
}
}
... ...
... ... @@ -145,6 +145,8 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
} catch (Exception e) {
logger.error("[func=recommend][queryWord=" + queryWord + "]", e);
return defaultSuggestRecommendation();
} finally {
searchKeyWordService.recordSuggestRecom(queryWord);
}
}
... ...
... ... @@ -493,7 +493,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl
* @param paramMap
* @return
*/
private SearchApiResult getShopsInfo(Map<String, String> paramMap) {
public SearchApiResult getShopsInfo(Map<String, String> paramMap) {
try {
logger.info("[func=getShopsInfo][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
// 1、构建SearchParam
... ...
... ... @@ -271,7 +271,12 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
if (StringUtils.isNotEmpty(queryWord)) {
// 是否精确匹配
String accurateQuery = paramMap.get("accurate");
queryBuilder = "Y".equalsIgnoreCase(accurateQuery) ? QueryBuilders.matchQuery("standardKeyword", CharUtils.standardized(queryWord)) : QueryBuilders.matchQuery("keyword.keyword_ik", queryWord);
if ("Y".equalsIgnoreCase(accurateQuery)) {
queryBuilder = QueryBuilders.matchQuery("standardKeyword", CharUtils.standardized(queryWord));
} else {
queryBuilder = QueryBuilders.multiMatchQuery(queryWord.trim().toLowerCase(), "keyword", "keyword.keyword_lowercase",
"keyword.keyword_pinyin", "keyword.keyword_jianpin", "keyword.keyword_ik");
}
}
searchParam.setQuery(queryBuilder);
... ...