Authored by Gino Zhang

优化代码结构

... ... @@ -36,6 +36,9 @@ public class ProductListServiceImpl implements IProductListService {
private static final Logger logger = LoggerFactory.getLogger(ProductListServiceImpl.class);
private static Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
// 当少于10个商品时 返回智能搜索词提示
private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 10;
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
... ... @@ -137,7 +140,7 @@ public class ProductListServiceImpl implements IProductListService {
// 1.3 搜索的数量小于10条
JSONObject dataMap = ((JSONObject) searchResult.getData());
if (dataMap.getLongValue("total") >= 10L) {
if (dataMap.getIntValue("total") >= SMART_SUGGESTION_PRODUCT_LIMIT) {
return false;
}
... ...
... ... @@ -50,6 +50,9 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
private static final String SUGGEST_PARAM_GLOBAL = "contain_global";
// 返回智能搜索词的数量
private static final int SMART_SUGGESTION_TERM_COUNT = 5;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
... ... @@ -263,7 +266,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
count++;
resultTerms.add(keyword);
// 最多返回五个推荐词
if (count == 5) {
if (count == SMART_SUGGESTION_TERM_COUNT) {
break;
}
}
... ... @@ -312,6 +315,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
if (CollectionUtils.isNotEmpty(searchResult.getResultList())) {
// 5) 从conversion获取的keyword列表
dest = (String) searchResult.getResultList().get(0).get("dest");
logger.info("[func=getTermsBySuggestConversion][source={}][dest={}]", searchResult.getResultList().get(0).get("source"), dest);
}
// 6) 加入缓存
... ... @@ -332,13 +336,13 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
.operator(MatchQueryBuilder.Operator.OR)
.minimumShouldMatch("20%");
// 根据关联的数量增加打分 _score = _score * 0.1 * log(count + 2)
// 根据关联的数量增加打分 _score = _score * 0.05 * log(count + 2)
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
functionScoreQueryBuilder.add(ScoreFunctionBuilders.fieldValueFactorFunction(countField).factor(0.1F).modifier(FieldValueFactorFunction.Modifier.LOG2P).missing(0));
functionScoreQueryBuilder.add(ScoreFunctionBuilders.fieldValueFactorFunction(countField).factor(0.05F).modifier(FieldValueFactorFunction.Modifier.LOG2P).missing(0));
searchParam.setQuery(queryBuilder);
searchParam.setPage(1);
searchParam.setSize(5);
searchParam.setSize(SMART_SUGGESTION_TERM_COUNT);
searchParam.setFiter(QueryBuilders.rangeQuery(countField).gte(20));
return searchParam;
}
... ...