Authored by wangnan

机器人客服权重影响打分

@@ -15,10 +15,14 @@ import com.yoho.search.service.utils.HttpServletRequestUtils; @@ -15,10 +15,14 @@ import com.yoho.search.service.utils.HttpServletRequestUtils;
15 import com.yoho.search.service.utils.SearchApiResultUtils; 15 import com.yoho.search.service.utils.SearchApiResultUtils;
16 import com.yoho.search.service.vo.SearchApiResult; 16 import com.yoho.search.service.vo.SearchApiResult;
17 import org.apache.commons.lang.StringUtils; 17 import org.apache.commons.lang.StringUtils;
  18 +import org.elasticsearch.common.lucene.search.function.CombineFunction;
  19 +import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
18 import org.elasticsearch.index.query.BoolQueryBuilder; 20 import org.elasticsearch.index.query.BoolQueryBuilder;
19 import org.elasticsearch.index.query.MatchQueryBuilder; 21 import org.elasticsearch.index.query.MatchQueryBuilder;
20 import org.elasticsearch.index.query.MultiMatchQueryBuilder; 22 import org.elasticsearch.index.query.MultiMatchQueryBuilder;
21 import org.elasticsearch.index.query.QueryBuilders; 23 import org.elasticsearch.index.query.QueryBuilders;
  24 +import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
  25 +import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
22 import org.elasticsearch.search.sort.SortBuilder; 26 import org.elasticsearch.search.sort.SortBuilder;
23 import org.elasticsearch.search.sort.SortBuilders; 27 import org.elasticsearch.search.sort.SortBuilders;
24 import org.elasticsearch.search.sort.SortOrder; 28 import org.elasticsearch.search.sort.SortOrder;
@@ -97,7 +101,11 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest @@ -97,7 +101,11 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest
97 queryBuilder.operator(MatchQueryBuilder.Operator.OR); 101 queryBuilder.operator(MatchQueryBuilder.Operator.OR);
98 queryBuilder.minimumShouldMatch(minimumShouldMatch); 102 queryBuilder.minimumShouldMatch(minimumShouldMatch);
99 queryBuilder.field("question", 200).field("keywords", 100); 103 queryBuilder.field("question", 200).field("keywords", 100);
100 - searchParam.setQuery(queryBuilder); 104 + //权重字段影响打分,_score = _score + log(1 + 1 * questionSeq)
  105 + FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
  106 + functionScoreQueryBuilder.add(ScoreFunctionBuilders.fieldValueFactorFunction("questionSeq").modifier(FieldValueFactorFunction.Modifier.LOG1P).factor(1.0f));
  107 + functionScoreQueryBuilder.boostMode(CombineFunction.SUM);
  108 + searchParam.setQuery(functionScoreQueryBuilder);
101 109
102 //4.配置Filter 110 //4.配置Filter
103 BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); 111 BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();