...
|
...
|
@@ -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;
|
|
|
}
|
...
|
...
|
|