All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.es.plus.adapter.params.EsHit Maven / Gradle / Ivy

There is a newer version: 0.3.3
Show newest version
package com.es.plus.adapter.params;

import com.es.plus.adapter.util.JsonUtils;
import lombok.Data;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Data
public class EsHit {
    /**
     * 数据
     */
    private String data;

    /**
     * es数据
     */
    private Map innerHitsMap = new ConcurrentHashMap<>();

//
//    /**
//     * 获取当前data的嵌套
//     */
//    public  EsHits getEsInnerHits(SFunction... function) {
//        StringJoiner sj = new StringJoiner(".");
//        for (SFunction rsFunction : function) {
//            sj.add(LambdaUtils.getFieldName(rsFunction));
//        }
//        String fieldName = sj.toString();
//        return getEsInnerHits(fieldName);
//    }
//
//    /**
//     * 获取当前data的嵌套list
//     */
//    public  List getList(Class tClass, SFunction... function) {
//        StringJoiner sj = new StringJoiner(".");
//        for (SFunction rsFunction : function) {
//            sj.add(LambdaUtils.getFieldName(rsFunction));
//        }
//        String fieldName = sj.toString();
//        return getList(tClass, fieldName);
//    }
//
//    /**
//     * 获取当前data的嵌套list的总数
//     */
//    public  long getInnerHitsTotal(SFunction... function) {
//        StringJoiner sj = new StringJoiner(".");
//        for (SFunction rsFunction : function) {
//            sj.add(LambdaUtils.getFieldName(rsFunction));
//        }
//        String fieldName = sj.toString();
//        return getInnerHitsTotal(fieldName);
//    }

    /**
     * 获取当前data的嵌套
     */
    public  EsHits getEsInnerHits(String fieldName) {
        return innerHitsMap.get(fieldName);
    }

    /**
     * 获取当前data的嵌套list
     */
    public  List getInnerList(Class tClass, String fieldName) {
        EsHits esHits = innerHitsMap.get(fieldName);
        if (esHits == null || esHits.getEsHitList() == null) {
            return new ArrayList<>();
        }
        List list = esHits.getEsHitList().stream().map(EsHit::getData).filter(Objects::nonNull)
                .map(d -> JsonUtils.toBean(d, tClass)).collect(Collectors.toList());
        return list;
    }

    /**
     * 获取当前data的嵌套list的总数
     */
    public  long getInnerHitsTotal(String fieldName) {
        EsHits esHits = innerHitsMap.get(fieldName);
        if (esHits == null) {
            return 0;
        }
        return esHits.getTotal();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy