|
@@ -1,12 +1,14 @@
|
|
|
package com.winhc.phoenix.example.util.company.search;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
|
|
import org.elasticsearch.index.query.*;
|
|
|
+import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.script.ScriptType;
|
|
|
import org.elasticsearch.search.rescore.QueryRescoreMode;
|
|
|
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
|
|
|
-import org.elasticsearch.search.rescore.RescoreBuilder;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
@@ -25,7 +27,9 @@ public class CompanySearchQueryUtils {
|
|
|
//以下为过滤逻辑
|
|
|
BoolQueryBuilder returnBoolQuery = boolQuery()
|
|
|
.filter(termQuery("deleted", "0"))
|
|
|
- .filter(rangeQuery("company_score_weight").gt(0.3F))
|
|
|
+ .filter(boolQuery().should(rangeQuery("company_score_weight").gt(0.3F))
|
|
|
+ .should(termsQuery("company_type", "2"))
|
|
|
+ )
|
|
|
.must(boolQuery);
|
|
|
|
|
|
Optional<List<Integer>> searchTypeList = Optional.ofNullable(companyQueryVo.getSearchTypeList());
|
|
@@ -56,14 +60,31 @@ public class CompanySearchQueryUtils {
|
|
|
return returnBoolQuery;
|
|
|
}
|
|
|
|
|
|
- public static List<RescoreBuilder> getReScoreBuilder(CompanyQueryVo companyQueryVo) {
|
|
|
+ public static QueryBuilder addScoreFunction(QueryBuilder query, CompanyQueryVo companyQueryVo) {
|
|
|
String content = companyQueryVo.getCleanupContent();
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>(2) {{
|
|
|
+ put("query_content", content);
|
|
|
+ put("der", 0.85);
|
|
|
+ }};
|
|
|
+
|
|
|
+ FunctionScoreQueryBuilder.FilterFunctionBuilder[] f = new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
|
|
|
+ new FunctionScoreQueryBuilder.FilterFunctionBuilder(new ScriptScoreFunctionBuilder(new Script(ScriptType.STORED, null, "company-name-term-score_v2", map)))
|
|
|
+ , new FunctionScoreQueryBuilder.FilterFunctionBuilder(new ScriptScoreFunctionBuilder(new Script(ScriptType.STORED, null, "company-search-script_v2", map)))
|
|
|
+// , new FunctionScoreQueryBuilder.FilterFunctionBuilder(new ScriptScoreFunctionBuilder(new Script(ScriptType.STORED, null, "company-search-script_v2", map)))
|
|
|
+ };
|
|
|
+
|
|
|
+ return new FunctionScoreQueryBuilder(query, f).boostMode(CombineFunction.MULTIPLY);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<QueryRescorerBuilder> getReScoreBuilder(CompanyQueryVo companyQueryVo) {
|
|
|
+ String content = CompanyIndexUtils.convertToSimplifiedChinese(companyQueryVo.getCleanupContent());
|
|
|
+
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(2) {{
|
|
|
put("query_content", content);
|
|
|
put("der", 0.85);
|
|
|
}};
|
|
|
- List<RescoreBuilder> list = new ArrayList<>();
|
|
|
+ List<QueryRescorerBuilder> list = new ArrayList<>();
|
|
|
|
|
|
//加上名称全匹配分数
|
|
|
list.add(new QueryRescorerBuilder(functionScoreQuery(new ScriptScoreFunctionBuilder(new Script(ScriptType.STORED, null, "company-name-term-score_v2", map))))
|
|
@@ -96,12 +117,16 @@ public class CompanySearchQueryUtils {
|
|
|
);
|
|
|
|
|
|
|
|
|
+ boolQuery.should(termQuery("cname.value", content).boost(0));
|
|
|
boolQuery.should(termQuery("org_number", org_content.toUpperCase()).boost(1000));
|
|
|
boolQuery.should(termQuery("credit_code", org_content.toUpperCase()).boost(1000));
|
|
|
boolQuery.should(termQuery("reg_number", org_content.toUpperCase()).boost(1000));
|
|
|
boolQuery.should(termQuery("icp_domain.keyword", org_content).boost(1000));
|
|
|
boolQuery.should(termQuery("emails.keyword", org_content).boost(1000));
|
|
|
- boolQuery.should(termQuery("phones", org_content).boost(1000));
|
|
|
+ boolQuery.should(disMaxQuery()
|
|
|
+ .add(termQuery("phones.keyword", org_content).boost(1000))
|
|
|
+ .add(matchQuery("phones", org_content).boost(1000))
|
|
|
+ );
|
|
|
boolQuery.should(termQuery("reg_location.keyword", org_content).boost(1000));
|
|
|
}
|
|
|
|
|
@@ -147,30 +172,52 @@ public class CompanySearchQueryUtils {
|
|
|
.tieBreaker(0.4F)
|
|
|
);
|
|
|
|
|
|
+ DisMaxQueryBuilder add = disMaxQuery().add(disMaxQuery()
|
|
|
+ .add(disMaxQuery()
|
|
|
+ .add(matchPhraseQuery("cname.show.pinyin", content))
|
|
|
+ .add(matchPhraseQuery("history_name.show.pinyin", content))
|
|
|
+ )
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
+ .minimumShouldMatch("5<90%")
|
|
|
+ .tieBreaker(0.3F)
|
|
|
+
|
|
|
+ .field("cname.show", 16)
|
|
|
+ .field("history_name.show", 12))
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
+ .operator(Operator.AND)
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
+ .tieBreaker(0.3F)
|
|
|
+ .field("cname.show.standard", 16)
|
|
|
+ .field("history_name.show.standard", 12))
|
|
|
+
|
|
|
+ .tieBreaker(0.4F));
|
|
|
+
|
|
|
+ String simplifiedChinese = CompanyIndexUtils.convertToSimplifiedChinese(org_content);
|
|
|
+ if (StringUtils.isNotBlank(simplifiedChinese)) {
|
|
|
+ //添加繁体字简化查询
|
|
|
+ add.add(disMaxQuery()
|
|
|
+ .add(disMaxQuery()
|
|
|
+ .add(matchPhraseQuery("cname.simplified_chinese.pinyin", simplifiedChinese))
|
|
|
+ .add(matchPhraseQuery("history_name.show.pinyin", simplifiedChinese))
|
|
|
+ )
|
|
|
+ .add(multiMatchQuery(simplifiedChinese)
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
+ .minimumShouldMatch("5<90%")
|
|
|
+ .tieBreaker(0.3F)
|
|
|
+
|
|
|
+ .field("cname.simplified_chinese", 16)
|
|
|
+ .field("history_name.simplified_chinese", 12))
|
|
|
+ .add(multiMatchQuery(simplifiedChinese)
|
|
|
+ .operator(Operator.AND)
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
+ .tieBreaker(0.3F)
|
|
|
+ .field("cname.simplified_chinese.standard", 16)
|
|
|
+ .field("history_name.simplified_chinese.standard", 12))
|
|
|
+ .tieBreaker(0.4F));
|
|
|
+ }
|
|
|
|
|
|
- boolQuery.should(
|
|
|
- disMaxQuery()
|
|
|
- .add(disMaxQuery()
|
|
|
- .add(matchPhraseQuery("cname.show.pinyin", content))
|
|
|
- .add(matchPhraseQuery("history_name.show.pinyin", content))
|
|
|
- )
|
|
|
- .add(multiMatchQuery(content)
|
|
|
- .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
- .minimumShouldMatch("5<90%")
|
|
|
- .tieBreaker(0.3F)
|
|
|
-
|
|
|
- .field("cname.show", 16)
|
|
|
- .field("history_name.show", 12))
|
|
|
- .add(multiMatchQuery(content)
|
|
|
- .operator(Operator.AND)
|
|
|
- .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
- .tieBreaker(0.3F)
|
|
|
- .field("cname.show.standard", 16)
|
|
|
- .field("history_name.show.standard", 12))
|
|
|
-
|
|
|
- .tieBreaker(0.4F)
|
|
|
- );
|
|
|
-
|
|
|
+ boolQuery.should(add);
|
|
|
return boolQuery;
|
|
|
}
|
|
|
|
|
@@ -196,4 +243,5 @@ public class CompanySearchQueryUtils {
|
|
|
return spanNearQueryBuilder;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|