Search in sources :

Example 1 with ESQueryBuilders

use of com.topcom.yzswf.util.es.ESQueryBuilders in project topcom-cloud by 545314690.

the class EsFileServiceImpl method search.

@Override
public com.topcom.yzswf.util.Page search(FileQueryVO fileQueryVO) throws Exception {
    String searchType = fileQueryVO.getSearchType();
    if (StringUtils.isNotBlank(searchType)) {
        if ("content".equals(searchType)) {
            searchType = "attachment.content";
        }
    } else {
        searchType = "filename";
    }
    PageRequest pageRequest = fileQueryVO.getPageRequest();
    ESQueryBuilderConstructor constructor = new ESQueryBuilderConstructor();
    QueryWord queryWord = fileQueryVO.getQueryWord();
    if (queryWord != null) {
        constructor.must(new ESQueryBuilders().queryString(searchType + ":" + queryWord.toQueryString()));
    }
    // 查询返回条数,最大 10000
    constructor.setSize(pageRequest.getLimit());
    // 分页查询条目起始位置, 默认0
    constructor.setFrom(pageRequest.getLimit() * (pageRequest.getPage() - 1));
    List<Order> orders = pageRequest.getOrders();
    if (StringUtils.isNotBlank(fileQueryVO.getType())) {
        constructor.must(new ESQueryBuilders().term("type", fileQueryVO.getType()));
    }
    if (StringUtils.isNotBlank(fileQueryVO.getSource())) {
        constructor.must(new ESQueryBuilders().term("source", fileQueryVO.getSource()));
    }
    if (CollectionUtils.isNotEmpty(fileQueryVO.getFileTypes())) {
        constructor.must(new ESQueryBuilders().terms("fileType", fileQueryVO.getFileTypes()));
    }
    if (StringUtils.isNotBlank(fileQueryVO.getAccidentType())) {
        constructor.must(new ESQueryBuilders().term("accidentType", fileQueryVO.getAccidentType()));
    }
    DateParam dateParam = fileQueryVO.getDateParam();
    if (dateParam != null) {
        Date startDate = dateParam.startDate();
        Date endDate = dateParam.endDate();
        constructor.must(new ESQueryBuilders().range("uploadTime", startDate.getTime(), endDate.getTime()));
    }
    if (orders != null && orders.size() > 0) {
        Order order = orders.get(0);
        Sort.Direction direction = order.getDirection();
        if (Sort.Direction.ASC.equals(direction)) {
            // 排序
            constructor.setAsc(order.getOrderBy());
        } else {
            // 排序
            constructor.setDesc(order.getOrderBy());
        }
    }
    // 
    com.topcom.yzswf.util.Page page = elasticSearchService.search(EsConf.INDEX, EsConf.TYPE, constructor);
    return page;
}
Also used : Order(com.topcom.cms.common.page.Order) ESQueryBuilderConstructor(com.topcom.yzswf.util.es.ESQueryBuilderConstructor) Date(java.util.Date) PageRequest(com.topcom.cms.common.page.PageRequest) QueryWord(com.topcom.yzswf.util.QueryWord) Sort(org.springframework.data.domain.Sort) ESQueryBuilders(com.topcom.yzswf.util.es.ESQueryBuilders) DateParam(com.topcom.cms.common.page.DateParam)

Aggregations

DateParam (com.topcom.cms.common.page.DateParam)1 Order (com.topcom.cms.common.page.Order)1 PageRequest (com.topcom.cms.common.page.PageRequest)1 QueryWord (com.topcom.yzswf.util.QueryWord)1 ESQueryBuilderConstructor (com.topcom.yzswf.util.es.ESQueryBuilderConstructor)1 ESQueryBuilders (com.topcom.yzswf.util.es.ESQueryBuilders)1 Date (java.util.Date)1 Sort (org.springframework.data.domain.Sort)1