Преглед на файлове

add: 添加不同版本搜索

- 用于固定不同索引的搜索版本效果
许家凯 преди 4 години
родител
ревизия
fb6f0a7dbd

+ 59 - 0
src/main/java/com/winhc/phoenix/example/controller/SearchController.java

@@ -0,0 +1,59 @@
+package com.winhc.phoenix.example.controller;
+
+import com.aliyun.odps.utils.StringUtils;
+import com.winhc.phoenix.example.aspect.Timer;
+import com.winhc.phoenix.example.enums.EsVersion;
+import com.winhc.phoenix.example.service.SearchService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/19 14:51
+ */
+@Slf4j
+@AllArgsConstructor
+@RestController
+@Api(tags = "es查询", value = "es")
+@RequestMapping("es/{version}")
+public class SearchController {
+    private final Map<String, SearchService> map;
+
+    @Timer
+    @ApiOperation(value = "es搜索")
+    @GetMapping("query")
+    public Object query(String content, @RequestParam(defaultValue = "v8_simp") EsVersion version, @RequestParam(defaultValue = "0") int from, @RequestParam(defaultValue = "10") int size) {
+        return map.get(version.getValue()).query(cleanup(content), from, size);
+    }
+
+
+    @Timer
+    @ApiOperation(value = "搜索对照组")
+    @GetMapping("control")
+    public Object controlGroup(String content, @RequestParam(defaultValue = "v8_simp") EsVersion version) {
+        return map.get(version.getValue()).controlGroup(cleanup(content));
+    }
+
+    @Timer
+    @ApiOperation(value = "搜索提示(测试中)")
+    @GetMapping("tips")
+    public Object searchTips(String content, @RequestParam(defaultValue = "v8_simp") EsVersion version) {
+        return map.get(version.getValue()).tips(cleanup(content));
+    }
+
+
+    private static final Pattern pattern = Pattern.compile("[^\\u4e00-\\u9fa50-9a-zA-Z]");
+
+    private static String cleanup(String val) {
+        return StringUtils.isNotBlank(val) ? pattern.matcher(val).replaceAll("") : "";
+    }
+}

+ 14 - 0
src/main/java/com/winhc/phoenix/example/dao/SearchDao.java

@@ -0,0 +1,14 @@
+package com.winhc.phoenix.example.dao;
+
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
+import org.elasticsearch.search.sort.SortBuilder;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/20 15:15
+ */
+public interface SearchDao {
+
+    Object search(String index, String type, QueryBuilder query, SortBuilder sortBuilder, FetchSourceContext fetchSourceContext, int from, int size);
+}

+ 76 - 0
src/main/java/com/winhc/phoenix/example/dao/impl/SearchDaoImpl.java

@@ -0,0 +1,76 @@
+package com.winhc.phoenix.example.dao.impl;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.winhc.phoenix.example.dao.SearchDao;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
+import org.elasticsearch.search.sort.SortBuilder;
+import org.springframework.stereotype.Repository;
+
+import java.util.HashMap;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/20 15:16
+ */
+@Slf4j
+@Repository
+@AllArgsConstructor
+public class SearchDaoImpl implements SearchDao {
+    private RestHighLevelClient restHighLevelClient;
+
+
+    private ObjectMapper mapper;
+    private static final TypeReference<HashMap<String, Object>> typeRef
+            = new TypeReference<HashMap<String, Object>>() {
+    };
+
+    @SneakyThrows
+    @Override
+    public Object search(String index, String type, QueryBuilder query, SortBuilder sortBuilder, FetchSourceContext fetchSourceContext, int from, int size) {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
+                .query(query)
+                .from(from)
+                .size(size)
+                .highlighter(new HighlightBuilder().field("*").preTags("<font color='red'>").postTags("</font>"));
+
+        if (fetchSourceContext != null) {
+            searchSourceBuilder.fetchSource(fetchSourceContext);
+        }
+        if (sortBuilder != null) {
+            searchSourceBuilder.sort(sortBuilder).trackScores(true);
+        }
+
+        SearchRequest searchRequest = new SearchRequest()
+                .indices(index)
+                .types(type)
+                .source(searchSourceBuilder);
+
+        SearchResponse search = restHighLevelClient.search(searchRequest);
+        return mapper.readValue(search.toString(), typeRef);
+    }
+
+
+    private final RestClient restClient;
+
+    @SneakyThrows
+    public Object test() {
+        Response get = restClient.performRequest("get", "_cat/indices/judicial_case_v*?h=index");
+        String s = EntityUtils.toString(get.getEntity());
+        System.out.println(s);
+
+        return null;
+    }
+}

+ 20 - 0
src/main/java/com/winhc/phoenix/example/enums/EsVersion.java

@@ -0,0 +1,20 @@
+package com.winhc.phoenix.example.enums;
+
+import com.winhc.phoenix.example.service.impl.SearchV7ServiceImpl;
+import com.winhc.phoenix.example.service.impl.SearchV8ServiceImpl;
+import com.winhc.phoenix.example.service.impl.SearchV8SimpServiceImpl;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author: XuJiakai
+ * 2020/12/8 19:04
+ */
+@Getter
+@AllArgsConstructor
+public enum EsVersion {
+    v7(SearchV7ServiceImpl.index),
+    v8_simp(SearchV8SimpServiceImpl.index),
+    v8(SearchV8ServiceImpl.index);
+    private final String value;
+}

+ 45 - 0
src/main/java/com/winhc/phoenix/example/job/EsScanJob.java

@@ -0,0 +1,45 @@
+package com.winhc.phoenix.example.job;
+
+import com.mongodb.client.MongoCollection;
+import com.winhc.phoenix.example.framework.es.EsFastScan;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.bson.Document;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.search.SearchHit;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/16 20:03
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+public class EsScanJob {
+    private RestHighLevelClient restHighLevelClient;
+    private final MongoTemplate mongoTemplate;
+
+    public void start() {
+        MongoCollection<Document> person = mongoTemplate.getCollection("person_xjk_20201117");
+        Consumer<SearchHit[]> func = list -> {
+            List<Document> documents = Arrays.stream(list).map(hit -> {
+                String id = hit.getId();
+                Document document = new Document(hit.getSourceAsMap());
+                document.put("_id", id);
+                return document;
+            }).collect(Collectors.toList());
+//            person.insertMany(documents);
+        };
+
+        new EsFastScan(restHighLevelClient, func, "dishonest-executed-person-v2", "person").scan();
+//        new EsFastScan(restHighLevelClient, func, "winhc-company-test", "company").scan();
+    }
+
+}

+ 36 - 0
src/main/java/com/winhc/phoenix/example/scheduled/ElasticsearchTask.java

@@ -0,0 +1,36 @@
+package com.winhc.phoenix.example.scheduled;
+
+import com.winhc.phoenix.example.service.SearchService;
+import com.winhc.phoenix.example.service.impl.SearchV8SimpServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author: XuJiakai
+ * 2020/12/2 10:11
+ */
+@Component
+@Slf4j
+public class ElasticsearchTask {
+    public ElasticsearchTask(@Qualifier(SearchV8SimpServiceImpl.index) SearchService searchService) {
+        this.searchService = searchService;
+    }
+
+    private final SearchService searchService;
+    private static final String[] keywords = new String[]{"所", "厂", "店", "公司", "县", "市", "省", "区", "场", "会"};
+    private static int i = 0;
+
+    @Scheduled(cron = "0 0/1 * * * ? ")
+    public void preheat() {
+        i = ++i % keywords.length;
+        int size = (int) (Math.random() * 9 + 1);
+//        String k = keywords[(int) (Math.random() * keywords.length)];
+        String k = keywords[i];
+        log.info("preheat index {} {}...", k, size);
+        Object query = searchService.query(k, size, size);
+        log.info("{}", query);
+        log.info("preheat successfully !");
+    }
+}

+ 13 - 0
src/main/java/com/winhc/phoenix/example/service/SearchService.java

@@ -0,0 +1,13 @@
+package com.winhc.phoenix.example.service;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/19 14:52
+ */
+public interface SearchService {
+    Object tips(String s);
+
+    Object controlGroup(String s);
+
+    Object query(String s,int from,int size);
+}

+ 124 - 0
src/main/java/com/winhc/phoenix/example/service/impl/SearchV7ServiceImpl.java

@@ -0,0 +1,124 @@
+package com.winhc.phoenix.example.service.impl;
+
+import com.winhc.phoenix.example.dao.impl.SearchDaoImpl;
+import com.winhc.phoenix.example.service.SearchService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.common.lucene.search.function.CombineFunction;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.MultiMatchQueryBuilder;
+import org.elasticsearch.index.query.Operator;
+import org.elasticsearch.index.query.QueryBuilders;
+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.fetch.subphase.FetchSourceContext;
+import org.elasticsearch.search.sort.ScriptSortBuilder;
+import org.elasticsearch.search.sort.SortOrder;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.elasticsearch.index.query.QueryBuilders.*;
+
+/**
+ * @author: XuJiakai
+ * 2020/12/7 10:58
+ */
+@Slf4j
+@Service(SearchV7ServiceImpl.index)
+@AllArgsConstructor
+public class SearchV7ServiceImpl implements SearchService {
+
+
+    private SearchDaoImpl searchDao;
+    private static final ScriptSortBuilder scriptSortBuilder = fastDefaultSort();
+
+    public static final String index = "winhc-company-v7";
+    public static final String type = "company";
+
+    private static final String[] includes = new String[]{"cname", "estiblish_time", "reg_status", "company_type", "province_code", "reg_capital", "logo"};
+    private static final FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, null);
+
+
+    private static final String[] includes_tips = new String[]{"cname.show"};
+    private static final FetchSourceContext fetchSourceContext_tips = new FetchSourceContext(true, includes_tips, null);
+
+    private BoolQueryBuilder getBoolQuery(String content) {
+        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
+        MultiMatchQueryBuilder multiMatchQueryBuilder = multiMatchQuery(content)
+                .operator(Operator.AND)
+                .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
+                .minimumShouldMatch("5<80%")
+                .tieBreaker(0.3F);
+
+        boolQuery.should(termQuery("cname.value.keyword", content).boost(100));
+        boolQuery.should(termQuery("history_name.value.keyword", content).boost(100));
+
+        multiMatchQueryBuilder
+                .field("cname.value", 16)
+                .field("history_name.value", 12)
+        ;
+
+
+        boolQuery.should(multiMatchQueryBuilder);
+        BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery();
+        boolQuery2.must(boolQuery);
+        boolQuery2.mustNot(QueryBuilders.existsQuery("current_id"));
+
+        return boolQuery2;
+
+    }
+
+
+    private static ScriptSortBuilder fastDefaultSort() {
+        Map<String, Object> params = new HashMap<>();
+        String script_inline =
+                "if(doc['cname.value.keyword'].value==null||doc['cname.value.keyword'].value.length()==3){" +
+                        "return 0.01;" +
+                        "}" +
+                        "if(doc['cname.value.keyword'].value.length()<=3){" +
+                        "return 0.3;" +
+                        "}" +
+                        "if(doc['reg_status'].value==null || doc['reg_status'].value.contains('销')){" +
+                        "return 1;" +
+                        "}" +
+                        "double a = doc['reg_capital_amount']==null?0.0:doc['reg_capital_amount'].value>1000000000000.0?1000000000000.0:doc['reg_capital_amount'].value;" +
+                        "double w = Math.log(a/10000000+1)+1;" +
+                        "if(doc['company_type'].value=='1'){" +
+                        "w=w+3;" +
+                        "}" +
+                        "return w;";
+
+        Script script = new Script(ScriptType.INLINE, "painless", script_inline, params);
+        return new ScriptSortBuilder(script, ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.DESC);
+
+    }
+
+    @Override
+    public Object tips(String s) {
+        BoolQueryBuilder boolQuery = getBoolQuery(s);
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .boostMode(CombineFunction.MULTIPLY);
+
+        return searchDao.search(index, type, function, null, fetchSourceContext_tips, 0, 5);
+    }
+
+    @Override
+    public Object controlGroup(String s) {
+        return searchDao.search(index, type, getBoolQuery(s), null, fetchSourceContext, 0, 10);
+    }
+
+    @Override
+    public Object query(String s, int from, int size) {
+        BoolQueryBuilder boolQuery = getBoolQuery(s);
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .boostMode(CombineFunction.MULTIPLY);
+
+        return searchDao.search(index, type, function, null, fetchSourceContext, from, size);
+    }
+}

+ 241 - 0
src/main/java/com/winhc/phoenix/example/service/impl/SearchV8ServiceImpl.java

@@ -0,0 +1,241 @@
+package com.winhc.phoenix.example.service.impl;
+
+import com.winhc.phoenix.example.dao.SearchDao;
+import com.winhc.phoenix.example.service.SearchService;
+import com.winhc.phoenix.example.util.SortUtil;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.common.lucene.search.function.CombineFunction;
+import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
+import org.elasticsearch.index.query.*;
+import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
+import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
+import org.elasticsearch.search.sort.ScriptSortBuilder;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+import java.util.regex.Pattern;
+
+import static org.elasticsearch.index.query.QueryBuilders.*;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/19 14:54
+ */
+@Slf4j
+@Primary
+@Service(value = SearchV8ServiceImpl.index)
+@AllArgsConstructor
+public class SearchV8ServiceImpl implements SearchService {
+    private SearchDao searchDao;
+
+    public static final String index = "winhc-company-v8";
+    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"};
+    private static final FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, null);
+
+    private static final String[] includes_tips = new String[]{"cname.show"};
+    private static final FetchSourceContext fetchSourceContext_tips = new FetchSourceContext(true, includes_tips, null);
+
+
+    @Override
+    public Object tips(String content) {
+        BoolQueryBuilder boolQuery = getBoolQuery(content);
+        ScriptSortBuilder scriptSortBuilder = SortUtil.getInstance().fastSort;
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM)
+                .boostMode(CombineFunction.MULTIPLY);
+
+        Object search = searchDao.search(index, type, function, null, fetchSourceContext_tips, 0, 5);
+        return search;
+    }
+
+    @Override
+    public Object controlGroup(String s) {
+        QueryBuilder boolQuery = getBoolQuery(s);
+        return searchDao.search(index, type, boolQuery, null, fetchSourceContext, 0, 10);
+    }
+
+    @Override
+    public Object query(String content, int from, int size) {
+        BoolQueryBuilder boolQuery = getBoolQuery(content);
+        ScriptSortBuilder scriptSortBuilder = SortUtil.getInstance().fastSort;
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .boostMode(CombineFunction.MULTIPLY);
+
+        Object search = searchDao.search(index, type, function, null, fetchSourceContext, from, size);
+        return search;
+    }
+
+
+    private BoolQueryBuilder getBoolQuery(String content) {
+        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
+
+
+//        boolQuery.should(matchPhrasePrefixQuery("cname.value.pinyin", content).analyzer("ik_pinyin_analyzer_search").maxExpansions(5).boost(0.1F));
+
+
+        boolQuery.should(termQuery("cname.value.keyword", content).boost(100));
+        boolQuery.should(termQuery("history_name.value.keyword", content).boost(100));
+
+        /*boolQuery.should(disMaxQuery().add(
+                QueryBuilders.boolQuery()
+                        .should(termQuery("legal_entity_name.keyword", content).boost(10))
+                        .should(termQuery("holder.name.keyword", content).boost(5.5F))
+                        .should(termQuery("staff.name.keyword", content).boost(5.5F))
+        ).tieBreaker(0.3F));*/
+
+
+        boolQuery.should(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));
+
+      /*  boolQuery.should(matchQuery("icp", content).boost(6));
+        boolQuery.should(matchQuery("app_info", content).boost(12));
+        boolQuery.should(matchQuery("company_tm", content).boost(5));*/
+
+
+//        boolQuery.should(termQuery("icp.keyword", content).boost(5));
+//        boolQuery.should(termQuery("app_info.keyword", content).boost(8));
+//        boolQuery.should(termQuery("company_tm.keyword", content).boost(5));
+
+   /*     boolQuery.should(disMaxQuery().add(
+                QueryBuilders.boolQuery()
+                        .should(termQuery("icp.keyword", content).boost(20))
+                        .should(termQuery("app_info.keyword", content).boost(40))
+                        .should(termQuery("company_tm.keyword", content).boost(20))
+                ).tieBreaker(0.3F)
+        );
+*/
+
+     /*   boolQuery.should(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.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))
+                )
+
+                /*   .add(
+                           disMaxQuery()
+                                   .add(matchQuery("icp", content).boost(8).operator(Operator.AND).minimumShouldMatch("5<80%"))
+                                   .add(matchQuery("app_info", content).boost(23).operator(Operator.AND).minimumShouldMatch("5<80%"))
+                                   .add(matchQuery("company_tm", content).boost(7).operator(Operator.AND).minimumShouldMatch("5<80%"))
+                                   .tieBreaker(0.3F)
+                   )*/
+
+             /*   .add(
+                        boolQuery()
+                                .should(matchQuery("icp", content).boost(8))
+                                .should(matchQuery("app_info", content).boost(23))
+                                .should(matchQuery("company_tm", content).boost(7))
+
+                                .should(termQuery("icp.keyword", content).boost(20))
+                                .should(termQuery("app_info.keyword", content).boost(40))
+                                .should(termQuery("company_tm.keyword", content).boost(15))
+                                .minimumShouldMatch("5<80%")
+
+                )*/
+
+                .add(
+                        disMaxQuery()
+                                .add(boolQuery().should(matchQuery("icp", content).boost(8)).minimumShouldMatch("5<80%"))
+                                .add(boolQuery().should(matchQuery("app_info", content).boost(19)).minimumShouldMatch("5<80%"))
+                                .add(boolQuery().should(matchQuery("company_tm", content).boost(7)).minimumShouldMatch("5<80%"))
+                                .tieBreaker(0.3F)
+
+                )
+
+                .tieBreaker(0.4F)
+        );
+
+
+      /*  boolQuery.should(disMaxQuery()
+                .tieBreaker(0.3F)
+
+                .add(matchQuery("icp", content).boost(6).minimumShouldMatch("5<80%"))
+                .add(matchQuery("app_info", content).boost(15).minimumShouldMatch("5<80%"))
+                .add(matchQuery("company_tm", content).boost(5).minimumShouldMatch("5<80%"))
+
+                .add(termQuery("icp.keyword", content).boost(20))
+                .add(termQuery("app_info.keyword", content).boost(40))
+                .add(termQuery("company_tm.keyword", content).boost(30))
+
+        );*/
+
+
+
+        /*  boolQuery.should(disMaxQuery()
+         *//*  .add(
+                        QueryBuilders.boolQuery()
+
+                                .should(matchQuery("icp", content).boost(6))
+                                .should(matchQuery("app_info", content).boost(15))
+                                .should(matchQuery("company_tm", content).boost(5))
+                                .minimumShouldMatch("5<80%")
+                )*//*
+                .add(
+                        QueryBuilders.boolQuery()
+                                .should(termQuery("icp.keyword", content).boost(20))
+                                .should(termQuery("app_info.keyword", content).boost(40))
+                                .should(termQuery("company_tm.keyword", content).boost(30))
+                )
+                .add(
+                        multiMatchQuery(content)
+                                .operator(Operator.AND)
+                                .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
+                                .minimumShouldMatch("5<90%")
+                                .tieBreaker(0.3F)
+                                .field("icp", 6)
+                                .field("app_info", 15)
+                                .field("company_tm", 5)
+                )
+                .tieBreaker(0.3F)
+        );*/
+
+     /*   boolQuery.should(multiMatchQuery(content)
+                .operator(Operator.AND)
+                .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
+                .tieBreaker(0.3F)
+                .field("icp", 3)
+                .field("app_info", 8)
+                .field("company_tm", 1.5F)
+        );*/
+
+        boolQuery.should(multiMatchQuery(content)
+                .operator(Operator.AND)
+                .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
+                .minimumShouldMatch("5<80%")
+                .tieBreaker(0.3F)
+                .field("cname.value", 16)
+                .field("history_name.value", 12)
+                .field("holder.name", 6)
+                .field("staff.name", 6)
+                .field("legal_entity_name", 6)
+
+        );
+
+
+        BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery();
+        boolQuery2.must(boolQuery);
+        return boolQuery2;
+
+    }
+
+    private static final Pattern pattern = Pattern.compile("^[a-zA-Z ]*$");
+
+    private static boolean is_pinyin(String str) {
+        return pattern.matcher(str).find();
+    }
+}

+ 114 - 0
src/main/java/com/winhc/phoenix/example/service/impl/SearchV8SimpServiceImpl.java

@@ -0,0 +1,114 @@
+package com.winhc.phoenix.example.service.impl;
+
+import com.winhc.phoenix.example.dao.SearchDao;
+import com.winhc.phoenix.example.service.SearchService;
+import com.winhc.phoenix.example.util.SortUtil;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.common.lucene.search.function.CombineFunction;
+import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.MultiMatchQueryBuilder;
+import org.elasticsearch.index.query.Operator;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
+import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
+import org.elasticsearch.search.sort.ScriptSortBuilder;
+import org.springframework.stereotype.Service;
+
+import static org.elasticsearch.index.query.QueryBuilders.*;
+
+/**
+ * @author: XuJiakai
+ * 2020/12/8 19:12
+ */
+@Slf4j
+@Service(SearchV8SimpServiceImpl.index)
+@AllArgsConstructor
+public class SearchV8SimpServiceImpl  implements SearchService {
+    private SearchDao searchDao;
+
+    public static final String index = "winhc-company-v8-simp";
+    public static final String type = "company";
+
+    private static final String[] includes_tips = new String[]{"cname.show","new_cid"};
+    private static final FetchSourceContext fetchSourceContext_tips = new FetchSourceContext(true, includes_tips, null);
+
+
+    @Override
+    public Object tips(String s) {
+        BoolQueryBuilder boolQuery = getBoolQuery(s);
+        ScriptSortBuilder scriptSortBuilder = SortUtil.getInstance().fastSort;
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM)
+                .boostMode(CombineFunction.MULTIPLY);
+
+        Object search = searchDao.search(index, type, function, null, fetchSourceContext_tips, 0, 5);
+        return search;
+    }
+
+    @Override
+    public Object controlGroup(String s) {
+        return searchDao.search(index, type, getBoolQuery(s), null, fetchSourceContext_tips, 0, 10);
+    }
+
+    @Override
+    public Object query(String s, int from, int size) {
+        BoolQueryBuilder boolQuery = getBoolQuery(s);
+        ScriptSortBuilder scriptSortBuilder = SortUtil.getInstance().fastSort;
+        FunctionScoreQueryBuilder function = functionScoreQuery(boolQuery, new ScriptScoreFunctionBuilder(scriptSortBuilder.script())
+        )
+                .boostMode(CombineFunction.MULTIPLY);
+
+        Object search = searchDao.search(index, type, function, null, fetchSourceContext_tips, from, size);
+        return search;
+    }
+
+
+    private BoolQueryBuilder getBoolQuery(String content) {
+        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
+        MultiMatchQueryBuilder multiMatchQueryBuilder = multiMatchQuery(content)
+                .operator(Operator.AND)
+                .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
+                .minimumShouldMatch("5<80%")
+                .tieBreaker(0.3F);
+
+        boolQuery.should(termQuery("cname.value.keyword", content).boost(100));
+        boolQuery.should(termQuery("history_name.value.keyword", content).boost(100));
+
+
+        boolQuery.should(disMaxQuery().add(
+                QueryBuilders.boolQuery()
+                        .should(termQuery("app_info.keyword", content).boost(40))
+                        .should(termQuery("company_tm.keyword", content).boost(20))
+                ).tieBreaker(0.3F)
+        );
+
+        boolQuery.should(disMaxQuery().add(
+                QueryBuilders.boolQuery()
+
+                        .should(matchQuery("app_info", content).boost(15))
+                        .should(matchQuery("company_tm", content).boost(5))
+
+                        .should(termQuery("app_info.keyword", content).boost(40))
+                        .should(termQuery("company_tm.keyword", content).boost(20))
+                        .minimumShouldMatch("5<80%")
+                ).tieBreaker(0.4F)
+        );
+
+
+        multiMatchQueryBuilder
+                .field("cname.value", 16)
+                .field("history_name.value", 12)
+        ;
+
+        boolQuery.should(multiMatchQueryBuilder);
+        BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery();
+        boolQuery2.must(boolQuery);
+        return boolQuery2;
+
+    }
+
+}

+ 40 - 0
src/main/java/com/winhc/phoenix/example/service/impl/SmsServiceImpl.java

@@ -0,0 +1,40 @@
+package com.winhc.phoenix.example.service.impl;
+
+import com.aliyun.openservices.ons.api.Message;
+import com.aliyun.openservices.ons.api.Producer;
+import com.aliyun.openservices.ons.api.SendResult;
+import com.winhc.phoenix.example.service.SmsService;
+import com.winhc.phoenix.example.vo.SmsBean;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: XuJiakai
+ * 2020/10/31 10:54
+ */
+@Slf4j
+@Service
+@AllArgsConstructor
+public class SmsServiceImpl implements SmsService {
+    private final Producer producer;
+
+    @Override
+    public boolean send(String msg, String to) {
+        return send(msg, new String[]{to});
+    }
+
+    @Override
+    public boolean send(String bean) {
+        Message message = new Message("test_sendmsg", "tag_ymt", bean.getBytes());
+        SendResult sendResult = producer.send(message);
+        assert sendResult != null;
+        return true;
+
+    }
+
+    @Override
+    public boolean send(String msg, String[] to) {
+        return send(new SmsBean(to, msg).toString());
+    }
+}