|
@@ -2,11 +2,12 @@ package com.winhc.phoenix.example.service.impl;
|
|
|
|
|
|
import com.winhc.phoenix.example.dao.SearchDao;
|
|
import com.winhc.phoenix.example.dao.SearchDao;
|
|
import com.winhc.phoenix.example.service.SearchService;
|
|
import com.winhc.phoenix.example.service.SearchService;
|
|
-import com.winhc.phoenix.example.util.SortUtil;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.elasticsearch.index.query.*;
|
|
import org.elasticsearch.index.query.*;
|
|
import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
|
|
import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
|
|
|
|
+import org.elasticsearch.script.Script;
|
|
|
|
+import org.elasticsearch.script.ScriptType;
|
|
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|
import org.elasticsearch.search.rescore.QueryRescoreMode;
|
|
import org.elasticsearch.search.rescore.QueryRescoreMode;
|
|
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
|
|
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
|
|
@@ -17,6 +18,8 @@ import org.elasticsearch.search.sort.SortOrder;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
|
@@ -32,7 +35,8 @@ import static org.elasticsearch.index.query.QueryBuilders.*;
|
|
public class SearchV8FastServiceImpl implements SearchService {
|
|
public class SearchV8FastServiceImpl implements SearchService {
|
|
private SearchDao searchDao;
|
|
private SearchDao searchDao;
|
|
|
|
|
|
- public static final String index = "winhc-company-v8";
|
|
|
|
|
|
+// public static final String index = "winhc-company-v8";
|
|
|
|
+ public static final String index = "winhc-company-v8_3";
|
|
public static final String type = "company";
|
|
public static final String type = "company";
|
|
private static final String[] includes = new String[]{"cname", "legal_entity*", "estiblish_time", "reg_status_std", "company_type", "province_code", "reg_capital", "logo", "new_cid"};
|
|
private static final String[] includes = new String[]{"cname", "legal_entity*", "estiblish_time", "reg_status_std", "company_type", "province_code", "reg_capital", "logo", "new_cid"};
|
|
private static final FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, null);
|
|
private static final FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, null);
|
|
@@ -50,7 +54,7 @@ public class SearchV8FastServiceImpl implements SearchService {
|
|
FieldSortBuilder company_score_weight = SortBuilders.fieldSort("company_score_weight").order(SortOrder.DESC);
|
|
FieldSortBuilder company_score_weight = SortBuilders.fieldSort("company_score_weight").order(SortOrder.DESC);
|
|
|
|
|
|
|
|
|
|
- Object search = searchDao.search(index, type, queryBuilder, company_score_weight, fetchSourceContext_tips, 0, 5);
|
|
|
|
|
|
+ Object search = searchDao.search(index, type, queryBuilder, company_score_weight, null, 0, 5);
|
|
return search;
|
|
return search;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -63,13 +67,17 @@ public class SearchV8FastServiceImpl implements SearchService {
|
|
@Override
|
|
@Override
|
|
public Object query(String content, int from, int size) {
|
|
public Object query(String content, int from, int size) {
|
|
BoolQueryBuilder boolQuery = getBoolQuery(content);
|
|
BoolQueryBuilder boolQuery = getBoolQuery(content);
|
|
- ScriptSortBuilder scriptSortBuilder = SortUtil.getInstance().fastSort;
|
|
|
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>() {{
|
|
|
|
+ put("query_content", content);
|
|
|
|
+ }};
|
|
|
|
+ ScriptSortBuilder scriptSortBuilder = new ScriptSortBuilder(new Script(ScriptType.STORED, null, "company-search-script", map), ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.DESC);
|
|
|
|
+
|
|
|
|
|
|
QueryRescorerBuilder rescorerBuilder = new QueryRescorerBuilder(functionScoreQuery(new ScriptScoreFunctionBuilder(scriptSortBuilder.script())))
|
|
QueryRescorerBuilder rescorerBuilder = new QueryRescorerBuilder(functionScoreQuery(new ScriptScoreFunctionBuilder(scriptSortBuilder.script())))
|
|
.windowSize(50)
|
|
.windowSize(50)
|
|
.setScoreMode(QueryRescoreMode.Multiply);
|
|
.setScoreMode(QueryRescoreMode.Multiply);
|
|
|
|
|
|
- Object search = searchDao.search(index, type, boolQuery, rescorerBuilder, null, fetchSourceContext, from, size);
|
|
|
|
|
|
+ Object search = searchDao.search(index, type, boolQuery, rescorerBuilder, null, fetchSourceContext_tips, from, size);
|
|
return search;
|
|
return search;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -77,23 +85,96 @@ public class SearchV8FastServiceImpl implements SearchService {
|
|
private BoolQueryBuilder getBoolQuery(String content) {
|
|
private BoolQueryBuilder getBoolQuery(String content) {
|
|
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
|
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
|
|
|
|
|
-
|
|
|
|
boolQuery.should(termQuery("cname.value.keyword", content).boost(1000));
|
|
boolQuery.should(termQuery("cname.value.keyword", content).boost(1000));
|
|
boolQuery.should(termQuery("history_name.value.keyword", content).boost(1000));
|
|
boolQuery.should(termQuery("history_name.value.keyword", content).boost(1000));
|
|
|
|
|
|
|
|
+ boolQuery.should(disMaxQuery()
|
|
|
|
+ .add(disMaxQuery()
|
|
|
|
+ .add(termQuery("legal_entity_name.keyword", content).boost(10))
|
|
|
|
+ .add(termQuery("holder.name.keyword", content).boost(5.5F))
|
|
|
|
+ .add(termQuery("staff.name.keyword", content).boost(5.5F))
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ ).add(disMaxQuery()
|
|
|
|
+
|
|
|
|
+ .add(matchQuery("legal_entity_name", content).boost(6).minimumShouldMatch("5<95%"))
|
|
|
|
+// .add(matchQuery("holder", content).boost(10).minimumShouldMatch("5<80%"))
|
|
|
|
+// .add(matchQuery("staff", content).boost(6).minimumShouldMatch("5<80%"))
|
|
|
|
+
|
|
|
|
+// .add(matchPhraseQuery("legal_entity_name", content).boost(6).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("holder.name", content).boost(10).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("staff.name", content).boost(6).slop(3))
|
|
|
|
+
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ ).tieBreaker(0.3F)
|
|
|
|
+ );
|
|
|
|
+ boolQuery.should(disMaxQuery()
|
|
|
|
+ .add(disMaxQuery()
|
|
|
|
+ .add(termQuery("icp.keyword", content).boost(20))
|
|
|
|
+ .add(termQuery("app_info.keyword", content).boost(40))
|
|
|
|
+ .add(termQuery("company_tm.keyword", content).boost(20))
|
|
|
|
+ .tieBreaker(0.4F))
|
|
|
|
+ .add(disMaxQuery()
|
|
|
|
+// .add(matchQuery("icp", content).boost(8).minimumShouldMatch("5"))
|
|
|
|
+// .add(matchQuery("app_info", content).boost(19).minimumShouldMatch("5"))
|
|
|
|
+// .add(matchQuery("company_tm", content).boost(7).minimumShouldMatch("5"))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ .add(matchPhraseQuery("icp", content).boost(8).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("app_info", content).boost(19).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("company_tm", content).boost(7).slop(3))
|
|
|
|
+
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ ).tieBreaker(0.4F)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ boolQuery.should(
|
|
|
|
+ disMaxQuery()
|
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
|
+ .minimumShouldMatch("5<90%")
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+
|
|
|
|
+ .field("cname.value", 16)
|
|
|
|
+ .field("history_name.value", 12))
|
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
|
+ .operator(Operator.AND)
|
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ .field("cname.value.standard", 16)
|
|
|
|
+ .field("history_name.value.standard", 12))
|
|
|
|
+ .tieBreaker(0.4F)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery()
|
|
|
|
+ .filter(termQuery("deleted", "0"))
|
|
|
|
+ .filter(rangeQuery("company_score_weight").gt(0.3F))
|
|
|
|
+ .must(boolQuery);
|
|
|
|
+ return boolQuery2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private BoolQueryBuilder getPersonQuery(String content) {
|
|
|
|
+ BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
|
|
|
+
|
|
|
|
+ boolQuery.should(termQuery("cname.value.keyword", content).boost(1000));
|
|
|
|
+ boolQuery.should(termQuery("history_name.value.keyword", content).boost(1000));
|
|
|
|
|
|
boolQuery.should(disMaxQuery()
|
|
boolQuery.should(disMaxQuery()
|
|
.add(disMaxQuery()
|
|
.add(disMaxQuery()
|
|
.add(termQuery("legal_entity_name.keyword", content).boost(10))
|
|
.add(termQuery("legal_entity_name.keyword", content).boost(10))
|
|
.add(termQuery("holder.name.keyword", content).boost(5.5F))
|
|
.add(termQuery("holder.name.keyword", content).boost(5.5F))
|
|
.add(termQuery("staff.name.keyword", content).boost(5.5F))
|
|
.add(termQuery("staff.name.keyword", content).boost(5.5F))
|
|
- .tieBreaker(0.3F))
|
|
|
|
- .add(disMaxQuery()
|
|
|
|
- .add(matchQuery("legal_entity_name", content).boost(6).minimumShouldMatch("5<80%"))
|
|
|
|
- .add(matchQuery("holder", content).boost(10).minimumShouldMatch("5<80%"))
|
|
|
|
- .add(matchQuery("staff", content).boost(6).minimumShouldMatch("5<80%"))
|
|
|
|
.tieBreaker(0.3F)
|
|
.tieBreaker(0.3F)
|
|
- ).tieBreaker(0.3F)
|
|
|
|
|
|
+ ).add(disMaxQuery()
|
|
|
|
+ .add(matchQuery("legal_entity_name", content).boost(6).minimumShouldMatch("5<95%"))
|
|
|
|
+ .add(matchPhraseQuery("holder.name", content).boost(10).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("staff.name", content).boost(6).slop(3))
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ )
|
|
|
|
+ .boost(2f)
|
|
|
|
+ .tieBreaker(0.3F)
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
@@ -102,28 +183,36 @@ public class SearchV8FastServiceImpl implements SearchService {
|
|
.add(termQuery("icp.keyword", content).boost(20))
|
|
.add(termQuery("icp.keyword", content).boost(20))
|
|
.add(termQuery("app_info.keyword", content).boost(40))
|
|
.add(termQuery("app_info.keyword", content).boost(40))
|
|
.add(termQuery("company_tm.keyword", content).boost(20))
|
|
.add(termQuery("company_tm.keyword", content).boost(20))
|
|
- .tieBreaker(0.4F)
|
|
|
|
- )
|
|
|
|
- .add(
|
|
|
|
- disMaxQuery()
|
|
|
|
- .add(matchQuery("icp", content).boost(8).minimumShouldMatch("5"))
|
|
|
|
- .add(matchQuery("app_info", content).boost(19).minimumShouldMatch("5"))
|
|
|
|
- .add(matchQuery("company_tm", content).boost(7).minimumShouldMatch("5"))
|
|
|
|
- .tieBreaker(0.3F)
|
|
|
|
- )
|
|
|
|
|
|
+ .tieBreaker(0.4F))
|
|
|
|
+ .add(disMaxQuery()
|
|
|
|
+ .add(matchPhraseQuery("icp", content).boost(8).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("app_info", content).boost(19).slop(3))
|
|
|
|
+ .add(matchPhraseQuery("company_tm", content).boost(7).slop(3))
|
|
|
|
|
|
- .tieBreaker(0.4F)
|
|
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ )
|
|
|
|
+ .boost(0.5f)
|
|
|
|
+ .tieBreaker(0.1F)
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
- boolQuery.should(multiMatchQuery(content)
|
|
|
|
-// .operator(Operator.AND)
|
|
|
|
- .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
|
- .minimumShouldMatch("5<85%")
|
|
|
|
- .tieBreaker(0.3F)
|
|
|
|
- .field("cname.value", 16)
|
|
|
|
- .field("history_name.value", 12)
|
|
|
|
|
|
+ boolQuery.should(
|
|
|
|
+ disMaxQuery()
|
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
|
+ .minimumShouldMatch("5<90%")
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
|
|
|
|
+ .field("cname.value", 16)
|
|
|
|
+ .field("history_name.value", 12))
|
|
|
|
+ .add(multiMatchQuery(content)
|
|
|
|
+ .operator(Operator.AND)
|
|
|
|
+ .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
|
|
|
|
+ .tieBreaker(0.3F)
|
|
|
|
+ .field("cname.value.standard", 16)
|
|
|
|
+ .field("history_name.value.standard", 12))
|
|
|
|
+ .boost(0.5f)
|
|
|
|
+ .tieBreaker(0.1F)
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
@@ -134,6 +223,7 @@ public class SearchV8FastServiceImpl implements SearchService {
|
|
return boolQuery2;
|
|
return boolQuery2;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private static final Pattern pattern = Pattern.compile("^[a-zA-Z ]*$");
|
|
private static final Pattern pattern = Pattern.compile("^[a-zA-Z ]*$");
|
|
|
|
|
|
private static boolean is_pinyin(String str) {
|
|
private static boolean is_pinyin(String str) {
|