Authored by 胡古飞

is_encode 的 BUG

package com.yoho.search.service.service;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
... ... @@ -289,7 +291,17 @@ public class SearchServiceHelper {
if (StringUtils.isBlank(keyword)) {
return QueryBuilders.matchAllQuery();
}
//0、处理is_encode的情况,编码转换
String is_encode = paramMap.get("is_encode");
if(StringUtils.isNotBlank(is_encode)&&is_encode.equals("1")){
try {
keyword = URLDecoder.decode(keyword, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn(e.getMessage(),e);
}
}
paramMap.put("query", keyword);
// 1、处理查询中包含性别的情况
this.dealKeywordOfGender(keyword, paramMap);
... ...
... ... @@ -148,7 +148,8 @@ public class SearchWithLocalCacheServiceImpl implements ISearchWithLocalCacheSer
public SearchApiResult productList(Map<String, String> paramMap) {
try {
logger.info("[func=productList][param={}][begin={}]", paramMap, System.currentTimeMillis());
//1)构造搜索参数
SearchParam searchParam = buildProductListSearchParam(paramMap);
// 5)从缓存中获取数据
... ... @@ -167,29 +168,17 @@ public class SearchWithLocalCacheServiceImpl implements ISearchWithLocalCacheSer
}
// 7)记录关键字对应的查询结果
String queryWord = paramMap.get("query");
//编码转换
String is_encode = paramMap.get("is_encode");
if(StringUtils.isNotBlank(is_encode)&&is_encode.equals("1")){
try {
queryWord = URLDecoder.decode(queryWord, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn(e.getMessage(),e);
}
}
if (!StringUtils.isBlank(queryWord) && !searchServiceHelper.isQuerySkn(queryWord)) {
searchKeyWordService.recordKeyWordByResultCount(queryWord, searchResult.getTotal());
}
// 8)当返回结果为空时,先记录请求参数,然后修改operator为or并重新搜索,minimum修改为50%
if (StringUtils.isNotBlank("queryWord") && 0 == searchResult.getTotal()) {
if (StringUtils.isNotBlank(queryWord) && 0 == searchResult.getTotal()) {
searchKeyWordService.handleEmptyRecords(paramMap);
logger.info("search result is empty by operator of AND, will use operator of OR to reenforce search result");
searchParam.setQuery(searchServiceHelper.constructOrQueryBuilder(paramMap));
searchResult = searchCommonService.doSearch(indexName, searchParam);
}
// 9)构造返回结果
JSONObject dataMap = new JSONObject();
dataMap.put("total", searchResult.getTotal());
... ...