package com.yeejoin.amos.boot.module.statistcs.biz.utils;

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

public class QueryBuilderUtils {
    // 复制BoolQueryBuilder
    public static BoolQueryBuilder copyBoolQuery(BoolQueryBuilder original) {
        if (original == null) {
            return QueryBuilders.boolQuery();
        }

        BoolQueryBuilder copy = QueryBuilders.boolQuery();

        // 复制查询条件
        original.must().forEach(copy::must);
        original.filter().forEach(copy::filter);
        original.should().forEach(copy::should);
        original.mustNot().forEach(copy::mustNot);

        // 复制minimumShouldMatch设置（新版本方式）
        if (original.minimumShouldMatch() != null) {
            copy.minimumShouldMatch(original.minimumShouldMatch());
        }

        // 复制其他属性
        copy.boost(original.boost());
        copy.queryName(original.queryName());

        return copy;
    }
}