// Path: elasticservice/src/main/java/elasticsearch/searchservice/dsl/DSLGenerateService.java
// @Service
// public interface DSLGenerateService {
//     String fromQueryParam(QueryParam param);
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/CacheSearchService.java
// @Service
// public interface CacheSearchService {
//     QueryResp query(String body);
//     Integer count(String body);
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/QueryParam.java
// public class QueryParam {
//     private List<Meta> filter;
//     private Collection collection;
//     private String orderByField;
//     private String orderByOrder;
//     private Long channelId;
//     private Integer pageSize;
//     private Integer offSet;
//     private Boolean isCount = Boolean.FALSE;
// 
//     public List<Meta> getFilter() {
//         return filter;
//     }
// 
//     public void setFilter(List<Meta> filter) {
//         this.filter = filter;
//     }
// 
//     public Collection getCollection() {
//         return collection;
//     }
// 
//     public void setCollection(Collection collection) {
//         this.collection = collection;
//     }
// 
//     public String getOrderByField() {
//         return orderByField;
//     }
// 
//     public void setOrderByField(String orderByField) {
//         this.orderByField = orderByField;
//     }
// 
//     public String getOrderByOrder() {
//         return orderByOrder;
//     }
// 
//     public void setOrderByOrder(String orderByOrder) {
//         this.orderByOrder = orderByOrder;
//     }
// 
//     public Integer getPageSize() {
//         return pageSize;
//     }
// 
//     public void setPageSize(Integer pageSize) {
//         this.pageSize = pageSize;
//     }
// 
//     public Integer getOffSet() {
//         return offSet;
//     }
// 
//     public void setOffSet(Integer offSet) {
//         this.offSet = offSet;
//     }
// 
//     public Long getChannelId() {
//         return channelId;
//     }
// 
//     public void setChannelId(Long channelId) {
//         this.channelId = channelId;
//     }
// 
//     public Boolean getCount() {
//         return isCount;
//     }
// 
//     public void setCount(Boolean count) {
//         isCount = count;
//     }
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/QueryResp.java
// public class QueryResp {
//     Long total;
//     List<Long> productIds;
// 
//     public QueryResp() {
//     }
// 
//     public QueryResp(Long total) {
//         this.total = total;
//     }
// 
//     public QueryResp(ESQueryResponse response) {
//         total = response.getHit().getTotal();
//         productIds = new ArrayList<>();
//         for (Hits hitResult : response.getHit().getHits()) {
//             JsonObject object = hitResult.getSource();
//             Long id = object.get("id").getAsLong();
//             productIds.add(id);
//         }
//     }
// 
//     public QueryResp(ESSearchResp resp) {
//         total = resp.getHits().getTotal();
//         productIds = new ArrayList<>();
//         for (HitResult hitResult : resp.getHits().getHits()) {
//             productIds.add(hitResult.get_source().getId());
//         }
//     }
// 
//     public Long getTotal() {
//         return total;
//     }
// 
//     public void setTotal(Long total) {
//         this.total = total;
//     }
// 
//     public List<Long> getProductIds() {
//         return productIds;
//     }
// 
//     public void setProductIds(List<Long> productIds) {
//         this.productIds = productIds;
//     }
// }


import elasticsearch.searchservice.dsl.DSLGenerateService;
import elasticsearch.searchservice.models.CacheSearchService;
import elasticsearch.searchservice.models.QueryParam;
import elasticsearch.searchservice.models.QueryResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


    @Autowired
    private DSLGenerateService dslGenerateService;

    @Override
    public QueryResp doCount(QueryParam queryFromPHP) {
        if (queryFromPHP.getChannelId() == null) {
            logger.warn("Must have channelId for elasticsearch ");
            return null;
        }

        logger.info("start do count");
        queryFromPHP.setCount(true);
        String body = dslGenerateService.fromQueryParam(queryFromPHP);
        logger.info("count DSL \r\n " + body);
        Integer count = cacheSearchService.count(body);
        logger.info("count done " + count);
        return new QueryResp(count.longValue());
    }

    @Override
    public QueryResp doSearch(QueryParam queryFromPHP) {
        if (queryFromPHP.getChannelId() == null) {
            logger.warn("Must have channelId for elasticsearch ");
            return null;
        }

        logger.info("start do search");
        String body = dslGenerateService.fromQueryParam(queryFromPHP);
        logger.info("search DSL \r\n" + body);

// Path: elasticservice/src/main/java/elasticsearch/searchservice/dsl/DSLGenerateService.java
// @Service
// public interface DSLGenerateService {
//     String fromQueryParam(QueryParam param);
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/CacheSearchService.java
// @Service
// public interface CacheSearchService {
//     QueryResp query(String body);
//     Integer count(String body);
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/QueryParam.java
// public class QueryParam {
//     private List<Meta> filter;
//     private Collection collection;
//     private String orderByField;
//     private String orderByOrder;
//     private Long channelId;
//     private Integer pageSize;
//     private Integer offSet;
//     private Boolean isCount = Boolean.FALSE;
// 
//     public List<Meta> getFilter() {
//         return filter;
//     }
// 
//     public void setFilter(List<Meta> filter) {
//         this.filter = filter;
//     }
// 
//     public Collection getCollection() {
//         return collection;
//     }
// 
//     public void setCollection(Collection collection) {
//         this.collection = collection;
//     }
// 
//     public String getOrderByField() {
//         return orderByField;
//     }
// 
//     public void setOrderByField(String orderByField) {
//         this.orderByField = orderByField;
//     }
// 
//     public String getOrderByOrder() {
//         return orderByOrder;
//     }
// 
//     public void setOrderByOrder(String orderByOrder) {
//         this.orderByOrder = orderByOrder;
//     }
// 
//     public Integer getPageSize() {
//         return pageSize;
//     }
// 
//     public void setPageSize(Integer pageSize) {
//         this.pageSize = pageSize;
//     }
// 
//     public Integer getOffSet() {
//         return offSet;
//     }
// 
//     public void setOffSet(Integer offSet) {
//         this.offSet = offSet;
//     }
// 
//     public Long getChannelId() {
//         return channelId;
//     }
// 
//     public void setChannelId(Long channelId) {
//         this.channelId = channelId;
//     }
// 
//     public Boolean getCount() {
//         return isCount;
//     }
// 
//     public void setCount(Boolean count) {
//         isCount = count;
//     }
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/searchservice/models/QueryResp.java
// public class QueryResp {
//     Long total;
//     List<Long> productIds;
// 
//     public QueryResp() {
//     }
// 
//     public QueryResp(Long total) {
//         this.total = total;
//     }
// 
//     public QueryResp(ESQueryResponse response) {
//         total = response.getHit().getTotal();
//         productIds = new ArrayList<>();
//         for (Hits hitResult : response.getHit().getHits()) {
//             JsonObject object = hitResult.getSource();
//             Long id = object.get("id").getAsLong();
//             productIds.add(id);
//         }
//     }
// 
//     public QueryResp(ESSearchResp resp) {
//         total = resp.getHits().getTotal();
//         productIds = new ArrayList<>();
//         for (HitResult hitResult : resp.getHits().getHits()) {
//             productIds.add(hitResult.get_source().getId());
//         }
//     }
// 
//     public Long getTotal() {
//         return total;
//     }
// 
//     public void setTotal(Long total) {
//         this.total = total;
//     }
// 
//     public List<Long> getProductIds() {
//         return productIds;
//     }
// 
//     public void setProductIds(List<Long> productIds) {
//         this.productIds = productIds;
//     }
// }


// Path: elasticservice/src/main/java/elasticsearch/searchservice/SearchServiceImpl.java
import elasticsearch.searchservice.dsl.DSLGenerateService;
import elasticsearch.searchservice.models.CacheSearchService;
import elasticsearch.searchservice.models.QueryParam;
import elasticsearch.searchservice.models.QueryResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


    @Autowired
    private DSLGenerateService dslGenerateService;

    @Override
    public QueryResp doCount(QueryParam queryFromPHP) {
        if (queryFromPHP.getChannelId() == null) {
            logger.warn("Must have channelId for elasticsearch ");
            return null;
        }

        logger.info("start do count");
        queryFromPHP.setCount(true);
        String body = dslGenerateService.fromQueryParam(queryFromPHP);
        logger.info("count DSL \r\n " + body);
        Integer count = cacheSearchService.count(body);
        logger.info("count done " + count);
        return new QueryResp(count.longValue());
    }

    @Override
    public QueryResp doSearch(QueryParam queryFromPHP) {
        if (queryFromPHP.getChannelId() == null) {
            logger.warn("Must have channelId for elasticsearch ");
            return null;
        }

        logger.info("start do search");
        String body = dslGenerateService.fromQueryParam(queryFromPHP);
        logger.info("search DSL \r\n" + body);

        return cacheSearchService.query(body);
