//package com.storlead.sales.controller.es;
//
//import cn.hutool.core.util.StrUtil;
//import com.storlead.es.pojo.vo.EsGenericVO;
//import com.storlead.es.pojo.vo.EsQuerySimilarityVO;
//import com.storlead.es.server.EsSearchCustomerService;
//import com.storlead.framework.common.result.Result;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.apache.commons.lang3.tuple.Pair;
//import org.elasticsearch.index.query.BoolQueryBuilder;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.elasticsearch.script.Script;
//import org.elasticsearch.script.ScriptType;
//import org.elasticsearch.search.sort.SortBuilders;
//import org.elasticsearch.search.sort.SortOrder;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
//import org.springframework.data.elasticsearch.core.SearchHits;
//import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.Resource;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * @program: sp-sales-platform
// * @description:
// * @author: chenkq
// * @create: 2025-04-11 16:52
// */
//@RestController
//@RequestMapping("/elastic/search")
//@Api(tags = "销售: 公告相关接口")
//public class ElasticSearchApiController {
//
//    @Resource
//    private EsSearchCustomerService searchCustomerService;
//
//    @Resource
//    private ElasticsearchRestTemplate elasticsearchTemplate;
//
//    @ApiOperation(value = "模糊查询")
//    @PostMapping( "/listSimilarity")
//    public Result<?> searchDataSimilarity(@RequestBody EsGenericVO dto) {
//
//        List<EsQuerySimilarityVO> ds = searchCustomerService.listComparisonSimilarity(dto);
//        return Result.result(ds);
//    }
//
//    @ApiOperation(value = "模糊查询")
//    @PostMapping( "/listSimilarity1")
//    public Result<?> searchDataSimilarity1(@RequestBody EsGenericVO dto) {
//
//        String scriptSource = getAlgorithmScript();
//
//        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(QueryBuilders.scriptScoreQuery(
//                        QueryBuilders.matchAllQuery(),
//                        new Script(
//                                ScriptType.INLINE,
//                                "painless",
//                                scriptSource,
//                                Map.of("field",dto.getFieldName(), "query", dto.getQueryText())
//                        )
//                ))
//                .withPageable(PageRequest.of(0, 100))
//                .build();
//
//        SearchHits<Map> hits = elasticsearchTemplate.search(
//                searchQuery,
//                Map.class,
//                IndexCoordinates.of(dto.getIndexName()));
//
//        List<EsCustomerVO> ds = hits.getSearchHits().stream()
//                .map(hit -> new EsCustomerVO(
//                        hit.getId(),
//                        (String) hit.getContent().get(dto.getFieldName()),
//                        (int) hit.getScore()))
//                .collect(Collectors.toList());
//
//        return Result.result(ds);
//    }
//
//    private String getAlgorithmScript() {
//        return "String s1 = doc[params.field].value;\n" +
//                "String s2 = params.query;\n" +
//                "int len1 = s1.length();\n" +
//                "int len2 = s2.length();\n" +
//                "int common = 0;\n" +
//                "int maxLen = Math.min(len1, len2);\n" +
//                "while (common < maxLen && s1.charAt(common) == s2.charAt(common)) {\n" +
//                "    common++;\n" +
//                "}\n" +
//                "return Math.round(100 * ((2.0 * common) / (len1 + len2)));";
//
//    }
//
//    @ApiOperation(value = "模糊查询")
//    @PostMapping( "/listSimilarity2")
//    public Result<?> findTop100Similar(@RequestBody EsGenericVO dto) {
//        String similarityScript = "\n" +
//                "def field = params.field;\n" +  // 使用参数传入字段名
//                "if (!doc.containsKey(field) || doc[field].size() == 0 || doc[field].value == null) {\n" +
//                "    return 0;\n" +
//                "}\n" +
//                "if (params.query == null) return 0;\n" +
//                "def docValue = doc[field].value;\n" +
//                "\n" +
//                "String s1 = docValue.toString();\n" +
//                "String s2 = params.query?.toString();\n" +
//                "\n" +
//                "// 空值检查\n" +
//                "if (s1 == null || s2 == null) return 0;\n" +
//                "\n" +
//                "// 完全匹配直接返回100\n" +
//                "if (s1.equals(s2)) return 100;\n" +
//                "\n" +
//                "// 计算编辑距离（内联实现）\n" +
//                "int s1_len = s1.length();\n" +
//                "int s2_len = s2.length();\n" +
//                "\n" +
//                "// 快速检查\n" +
//                "if (s1_len == 0) return (int)(100 * (1 - (s2_len / Math.max(1, s2_len))));\n" +
//                "if (s2_len == 0) return (int)(100 * (1 - (s1_len / Math.max(1, s1_len))));\n" +
//                "\n" +
//                "// 使用单数组优化空间复杂度\n" +
//                "int[] costs = new int[s2_len + 1];\n" +
//                "for (int j = 0; j <= s2_len; j++) {\n" +
//                "    costs[j] = j;\n" +
//                "}\n" +
//                "\n" +
//                "for (int i = 1; i <= s1_len; i++) {\n" +
//                "    costs[0] = i;\n" +
//                "    int prev = i - 1;\n" +
//                "    for (int j = 1; j <= s2_len; j++) {\n" +
//                "        int cost = (s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1;\n" +
//                "        int insertion = costs[j] + 1;\n" +
//                "        int deletion = costs[j - 1] + 1;\n" +
//                "        int substitution = prev + cost;\n" +
//                "        int current = insertion;\n" +
//                "        if (deletion < current) {\n" +
//                "           current = deletion;\n" +
//                "        } \n" +
//                "        if (substitution < current) {\n" +
//                "           current = substitution;\n" +
//                "        } \n" +
//                "        prev = costs[j];\n" +
//                "        costs[j] = current;\n" +
//                "    }\n" +
//                "}\n" +
//                "\n" +
//                "int distance = costs[s2_len];\n" +
//                "int maxLen = s1_len > s2_len ? s1_len : s2_len;\n" +
//                "if (maxLen == 0) return 100;\n"+
//                "\n" +
//                "// 计算相似度百分比(0-100)\n" +
//                "double similarity = 100 * (1 - ((double)distance / maxLen));\n" +
//                "return (int) Math.round(similarity);";
//
//        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(QueryBuilders.boolQuery()
//                        .must(QueryBuilders.scriptScoreQuery(
//                                QueryBuilders.matchAllQuery(),
//                                new Script(
//                                        ScriptType.INLINE,
//                                        "painless",
//                                        similarityScript,
//                                        Map.of("field",dto.getFieldName()+""+ (StrUtil.isNotBlank(dto.getFieldKey()) ? "."+dto.getFieldKey() : ""), "query", dto.getQueryText())
//                                )
//                        ))
//
//                )
//                .withMinScore(20.0f)  // 确保只返回≥50分的文档
//                .withSort(SortBuilders.scoreSort().order(SortOrder.DESC)) // 显式按分数降序
//                .withPageable(PageRequest.of(0, 100))
//                .build();
//
//
//        SearchHits<Map> hits = elasticsearchTemplate.search(
//                searchQuery,
//                Map.class,
//                IndexCoordinates.of(dto.getIndexName()));
//
//        List<EsCustomerVO> ds = hits.getSearchHits().stream()
//                .map(hit -> new EsCustomerVO(
//                        hit.getId(),
//                        (String) hit.getContent().get(dto.getFieldName()),
//                        (int) hit.getScore()))
//                .collect(Collectors.toList());
//
//        return Result.result(ds);
//    }
//
//    @ApiOperation(value = "模糊查询")
//    @PostMapping( "/listSimilarity3")
//    public Result<?> findTop100Similar3(@RequestBody EsGenericVO dto) {
////        String similarityScript = "\n" +
////                "def field = params.field;\n" +  // 使用参数传入字段名
////                "if (!doc.containsKey(field) || doc[field].size() == 0 || doc[field].value == null) {\n" +
////                "    return 0;\n" +
////                "}\n" +
////                "if (params.query == null) return 0;\n" +
////                "def docValue = doc[field].value;\n" +
////                "\n" +
////                "String s1 = docValue.toString();\n" +
////                "String s2 = params.query?.toString();\n" +
////                "\n" +
////                "// 空值检查\n" +
////                "if (s1 == null || s2 == null) return 0;\n" +
////                "\n" +
////                "// 完全匹配直接返回100\n" +
////                "if (s1.equals(s2)) return 100;\n" +
////                "\n" +
////                "// 计算编辑距离（内联实现）\n" +
////                "int s1_len = s1.length();\n" +
////                "int s2_len = s2.length();\n" +
////                "\n" +
////                "// 快速检查\n" +
////                "if (s1_len == 0) return (int)(100 * (1 - (s2_len / Math.max(1, s2_len))));\n" +
////                "if (s2_len == 0) return (int)(100 * (1 - (s1_len / Math.max(1, s1_len))));\n" +
////                "\n" +
////                "// 使用单数组优化空间复杂度\n" +
////                "int[] costs = new int[s2_len + 1];\n" +
////                "for (int j = 0; j <= s2_len; j++) {\n" +
////                "    costs[j] = j;\n" +
////                "}\n" +
////                "\n" +
////                "for (int i = 1; i <= s1_len; i++) {\n" +
////                "    costs[0] = i;\n" +
////                "    int prev = i - 1;\n" +
////                "    for (int j = 1; j <= s2_len; j++) {\n" +
////                "        int cost = (s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1;\n" +
////                "        int insertion = costs[j] + 1;\n" +
////                "        int deletion = costs[j - 1] + 1;\n" +
////                "        int substitution = prev + cost;\n" +
////                "        int current = insertion;\n" +
////                "        if (deletion < current) {\n" +
////                "           current = deletion;\n" +
////                "        } \n" +
////                "        if (substitution < current) {\n" +
////                "           current = substitution;\n" +
////                "        } \n" +
////                "        prev = costs[j];\n" +
////                "        costs[j] = current;\n" +
////                "    }\n" +
////                "}\n" +
////                "\n" +
////                "int distance = costs[s2_len];\n" +
////                "int maxLen = s1_len > s2_len ? s1_len : s2_len;\n" +
////                "if (maxLen == 0) return 100;\n"+
////                "\n" +
////                "// 计算相似度百分比(0-100)\n" +
////                "double similarity = 100 * (1 - ((double)distance / maxLen));\n" +
////                "return (int) Math.round(similarity);";
//
////        String similarityScript = "\n" +
////                "def field = params.field;\n" +
////                "if (!doc.containsKey(field) || doc[field].size() == 0 || doc[field].value == null) {\n" +
////                "    return 0;\n" +
////                "}\n" +
////                "if (params.query == null) return 0;\n" +
////                "def docValue = doc[field].value;\n" +
////                "\n" +
////                "String s1 = docValue.toString();\n" +
////                "String s2 = params.query?.toString();\n" +
////                "\n" +
////                "// 空值检查\n" +
////                "if (s1 == null || s2 == null) return 0;\n" +
////                "\n" +
////                "// 完全匹配直接返回100\n" +
////                "if (s1.equals(s2)) return 100;\n" +
////                "\n" +
////                "// 计算编辑距离（内联实现）\n" +
////                "int s1_len = s1.length();\n" +
////                "int s2_len = s2.length();\n" +
////                "\n" +
////                "// 快速检查\n" +
////                "if (s1_len == 0) {\n" +
////                "    if (s2_len == 0) { return 100; }\n" +
////                "    else { return 0; }\n" +
////                "}\n" +
////                "if (s2_len == 0) return 0;\n" +
////                "\n" +
////                "// 使用单数组优化空间复杂度\n" +
////                "int[] costs = new int[s2_len + 1];\n" +
////                "for (int j = 0; j <= s2_len; j++) {\n" +
////                "    costs[j] = j;\n" +
////                "}\n" +
////                "\n" +
////                "for (int i = 1; i <= s1_len; i++) {\n" +
////                "    costs[0] = i;\n" +
////                "    int prev = i - 1;\n" +
////                "    for (int j = 1; j <= s2_len; j++) {\n" +
////                "        int cost = (s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1;\n" +
////                "        int insertion = costs[j] + 1;\n" +
////                "        int deletion = costs[j - 1] + 1;\n" +
////                "        int substitution = prev + cost;\n" +
////                "        \n" +
////                "        // 手动实现最小值计算\n" +
////                "        int current = insertion;\n" +
////                "        if (deletion < current) { current = deletion; }\n" +
////                "        if (substitution < current) { current = substitution; }\n" +
////                "        \n" +
////                "        prev = costs[j];\n" +
////                "        costs[j] = current;\n" +
////                "    }\n" +
////                "}\n" +
////                "\n" +
////                "int distance = costs[s2_len];\n" +
////                "// 手动实现最大值计算\n" +
////                "int maxLen = s1_len;\n" +
////                "if (s2_len > maxLen) { maxLen = s2_len; }\n" +
////                "\n" +
////                "// 计算相似度百分比(0-100)\n" +
////                "double similarity = 100 * (1 - ((double)distance / maxLen));\n" +
////                "\n" +
////                "// 手动实现0-100范围限制\n" +
////                "int result = (int) similarity;\n" +
////                "if (result > 100) { result = 100; }\n" +
////                "else if (result < 0) { result = 0; }\n" +
////                "\n" +
////                "return result;";
//
//        String similarityScript = "\n" +
//                "def field = params.field;\n" +  // 使用参数传入字段名
//                "if (!doc.containsKey(field) || doc[field].size() == 0 || doc[field].value == null) {\n" +
//                "    return 0;\n" +
//                "}\n" +
//                "if (params.query == null) return 0;\n" +
//                "def docValue = doc[field].value;\n" +
//                "\n" +
//                "String s1 = docValue.toString();\n" +
//                "String s2 = params.query?.toString();\n" +
//                "\n" +
//                "// 空值检查\n" +
//                "if (s1 == null || s2 == null) return 0;\n" +
//                "\n" +
//                "// 完全匹配直接返回100\n" +
//                "if (s1.equals(s2)) return 100;\n" +
//                "\n" +
//                "// 计算编辑距离（内联实现）\n" +
//                "int s1_len = s1.length();\n" +
//                "int s2_len = s2.length();\n" +
//                "\n" +
//                "// 快速检查\n" +
//                "if (s1_len == 0) return (int)(100 * (1 - (s2_len / Math.max(1, s2_len))));\n" +
//                "if (s2_len == 0) return (int)(100 * (1 - (s1_len / Math.max(1, s1_len))));\n" +
//                "\n" +
//                "// 使用单数组优化空间复杂度\n" +
//                "int[] costs = new int[s2_len + 1];\n" +
//                "for (int j = 0; j <= s2_len; j++) {\n" +
//                "    costs[j] = j;\n" +
//                "}\n" +
//                "\n" +
//                "for (int i = 1; i <= s1_len; i++) {\n" +
//                "    costs[0] = i;\n" +
//                "    int prev = i - 1;\n" +
//                "    for (int j = 1; j <= s2_len; j++) {\n" +
//                "        int cost = (s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1;\n" +
//                "        int insertion = costs[j] + 1;\n" +
//                "        int deletion = costs[j - 1] + 1;\n" +
//                "        int substitution = prev + cost;\n" +
//                "        int current = insertion;\n" +
//                "        if (deletion < current) {\n" +
//                "           current = deletion;\n" +
//                "        } \n" +
//                "        if (substitution < current) {\n" +
//                "           current = substitution;\n" +
//                "        } \n" +
//                "        prev = costs[j];\n" +
//                "        costs[j] = current;\n" +
//                "    }\n" +
//                "}\n" +
//                "\n" +
//                "int distance = costs[s2_len];\n" +
//                "int maxLen = s1_len > s2_len ? s1_len : s2_len;\n" +
//                "if (maxLen == 0) return 100;\n"+
//                "\n" +
//                "// 计算相似度百分比(0-100)\n" +
//                "double similarity = 100 * (1 - ((double)distance / maxLen));\n" +
//                "return (int) Math.round(similarity);";
//
//        Map<String, List<String>> indexFieldsMap = Map.of(
//                "customer_company_data_index", Arrays.asList("email.keyword", "email1.keyword", "email2.keyword", "email3.keyword"),
//                "liaison_data_index", Arrays.asList("email.keyword", "email1.keyword", "email2.keyword", "email3.keyword")
//        );
//
////        List<Map.Entry<String, String>> fieldIndexPairs = Arrays.asList(
////                Map.entry("email.keyword", "customer_company_data_index"),
////                Map.entry("email1.keyword", "customer_company_data_index"),
////                Map.entry("email2.keyword", "customer_company_data_index"),
////                Map.entry("email3.keyword", "customer_company_data_index"),
////                Map.entry("email.keyword", "liaison_data_index"),
////                Map.entry("email1.keyword", "liaison_data_index"),
////                Map.entry("email2.keyword", "liaison_data_index"),
////                Map.entry("email3.keyword", "liaison_data_index")
////        );
//
//        // 2. 构建动态查询
//        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//        indexFieldsMap.forEach((indexName, fields) -> {
//            fields.forEach(field -> {
//                boolQuery.should(
//                        QueryBuilders.scriptScoreQuery(
//                                QueryBuilders.matchAllQuery(),
//                                new Script(
//                                        ScriptType.INLINE,
//                                        "painless",
//                                        similarityScript,
//                                        Map.of("field", field, "query", dto.getQueryText())
//                                )
//                        ).setMinScore(80.0f)
//                );
//            });
//        });
//
//        // 4. 构建最终查询
//        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(boolQuery.minimumShouldMatch(1))
//                .withSort(SortBuilders.scoreSort().order(SortOrder.DESC))
//                .withPageable(PageRequest.of(0, 100))
//                .build();
//
//        SearchHits<Map> hits = elasticsearchTemplate.search(
//                searchQuery,
//                Map.class,
//                IndexCoordinates.of("customer_company_data_index","liaison_data_index"));
//
//        List<Map> ds = hits.getSearchHits().stream()
//                .map(hit -> {
//                    Map<String, Object> content = new HashMap<>(hit.getContent()); // Create a copy
//                    content.put("similarityScore", hit.getScore());
//                    return content;
//                }).collect(Collectors.toList());
//
//        return Result.result(ds);
//    }
//
//    @ApiOperation(value = "模糊查询")
//    @PostMapping( "/listSimilarity4")
//    public Result<?> findTop100Similar4(@RequestBody EsGenericVO dto) {
//
//        String similarityScript = "\n" +
//                "def field = params.field;\n" +  // 使用参数传入字段名
//                "if (!doc.containsKey(field) || doc[field].size() == 0 || doc[field].value == null) {\n" +
//                "    return 0;\n" +
//                "}\n" +
//                "if (params.query == null) return 0;\n" +
//                "def docValue = doc[field].value;\n" +
//                "\n" +
//                "String s1 = docValue.toString();\n" +
//                "String s2 = params.query?.toString();\n" +
//                "\n" +
//                "// 空值检查\n" +
//                "if (s1 == null || s2 == null) return 0;\n" +
//                "\n" +
//                "// 完全匹配直接返回100\n" +
//                "if (s1.equals(s2)) return 100;\n" +
//                "\n" +
//                "// 计算编辑距离（内联实现）\n" +
//                "int s1_len = s1.length();\n" +
//                "int s2_len = s2.length();\n" +
//                "\n" +
//                "// 快速检查\n" +
//                "if (s1_len == 0) return (int)(100 * (1 - (s2_len / Math.max(1, s2_len))));\n" +
//                "if (s2_len == 0) return (int)(100 * (1 - (s1_len / Math.max(1, s1_len))));\n" +
//                "\n" +
//                "// 使用单数组优化空间复杂度\n" +
//                "int[] costs = new int[s2_len + 1];\n" +
//                "for (int j = 0; j <= s2_len; j++) {\n" +
//                "    costs[j] = j;\n" +
//                "}\n" +
//                "\n" +
//                "for (int i = 1; i <= s1_len; i++) {\n" +
//                "    costs[0] = i;\n" +
//                "    int prev = i - 1;\n" +
//                "    for (int j = 1; j <= s2_len; j++) {\n" +
//                "        int cost = (s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1;\n" +
//                "        int insertion = costs[j] + 1;\n" +
//                "        int deletion = costs[j - 1] + 1;\n" +
//                "        int substitution = prev + cost;\n" +
//                "        int current = insertion;\n" +
//                "        if (deletion < current) {\n" +
//                "           current = deletion;\n" +
//                "        } \n" +
//                "        if (substitution < current) {\n" +
//                "           current = substitution;\n" +
//                "        } \n" +
//                "        prev = costs[j];\n" +
//                "        costs[j] = current;\n" +
//                "    }\n" +
//                "}\n" +
//                "\n" +
//                "int distance = costs[s2_len];\n" +
//                "int maxLen = s1_len > s2_len ? s1_len : s2_len;\n" +
//                "if (maxLen == 0) return 100;\n"+
//                "\n" +
//                "// 计算相似度百分比(0-100)\n" +
//                "double similarity = 100 * (1 - ((double)distance / maxLen));\n" +
//                "return (int) Math.round(similarity);";
//
////        Map<String, List<String>> indexFieldsMap = Map.of(
////                "customer_company_data_index", Arrays.asList("email.keyword","email1.keyword","email2.keyword","email3.keyword")
////        );
//        Map<String, List<String>> indexFieldsMap = Map.of(
//                "test_customer_company_data_index", Arrays.asList("website.keyword","website1.keyword","website2.keyword","website3.keyword")
//        );
//
//// 保存索引名称和查询的列表
//        List<Pair<String, NativeSearchQuery>> indexQueries = new ArrayList<>();
//
//        float minScore = Float.parseFloat(dto.getMinScore());
//        indexFieldsMap.forEach((indexName, fields) -> {
//
//
//            for (int i = 0; i < fields.size(); i++) {
//                String field = fields.get(i);
//                Map<String, Object> scriptParams = new HashMap<>();
//                scriptParams.put("field", field);
//                scriptParams.put("query", dto.getQueryText());
//                scriptParams.put("targetIndex", indexName);
//                BoolQueryBuilder indexQuery = QueryBuilders.boolQuery();
//
//                indexQuery.should(
//                        QueryBuilders.scriptScoreQuery(
//                                QueryBuilders.matchAllQuery(),
//                                new Script(
//                                        ScriptType.INLINE,
//                                        "painless",
//                                        similarityScript,
//                                        scriptParams
//                                )
//                        ).setMinScore(minScore)
//                );
//                NativeSearchQuery indexSearchQuery = new NativeSearchQueryBuilder()
//                        .withQuery(indexQuery.minimumShouldMatch(1))
//                        .withSort(SortBuilders.scoreSort().order(SortOrder.DESC))
//                        .withPageable(PageRequest.of(0, 1000))
//                        .build();
//
//                indexQueries.add(Pair.of(indexName, indexSearchQuery));
//            }
//
//        });
//
//// 执行查询并合并结果
//        List<Map> combinedResults = new ArrayList<>();
//        for (Pair<String, NativeSearchQuery> pair : indexQueries) {
//            String indexName = pair.getLeft();
//            NativeSearchQuery query = pair.getRight();
//
//            SearchHits<Map> hits = elasticsearchTemplate.search(
//                    query,
//                    Map.class,
//                    IndexCoordinates.of(indexName));
//
//            hits.getSearchHits().stream()
//                    .map(hit -> {
//                        Map<String, Object> content = new HashMap<>(hit.getContent());
//                        content.put("similarityScore", hit.getScore());
//                        content.put("matchedIndex", hit.getIndex());
//                        return content;
//                    })
//                    .forEach(combinedResults::add);
//        }
//
//// 按相似度分数排序
//        combinedResults.sort((a, b) -> {
//            float scoreA = (float) a.getOrDefault("similarityScore", 0f);
//            float scoreB = (float) b.getOrDefault("similarityScore", 0f);
//            return Float.compare(scoreB, scoreA); // 降序排序
//        });
//        return Result.result(combinedResults);
//    }
//}
