@Override public IPagehealthManagerSearchByEs(PageParams healthManagerSearchVO) throws IOException { SearchRequest searchRequest = new SearchRequest(TenantConstants.DOCTOR); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // 分页 searchSourceBuilder.from((int) healthManagerSearchVO.getCurrent() - 1); searchSourceBuilder.size((int) healthManagerSearchVO.getSize()); // 过滤返回的字段 String[] fields = {"id", "doctorName", "avatar", "title", "workUnit", "department", "isEnable", "approvalStatus", "doctorType", "genius", "describe", "isOnline", "createTime"}; searchSourceBuilder.fetchSource(fields, null); // 排序 searchSourceBuilder.sort(new FieldSortBuilder("createTime").order(SortOrder.DESC)); String keyword = healthManagerSearchVO.getModel().getKeyword(); // 组合查询 must相当于sql中的and BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery("isOnline", true)) .must(QueryBuilders.matchQuery("isEnable", true)) .must(QueryBuilders.matchQuery("approvalStatus", DoctorApprovalStatus.PASS)); if (StrUtil.isNotBlank(keyword)) { // 多字段查询 multiMatchQuery boolQueryBuilder.must(QueryBuilders.multiMatchQuery(keyword, "doctorName", "genius")); } searchSourceBuilder.query(boolQueryBuilder); searchRequest.source(searchSourceBuilder); SearchResponse response = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); // 封装返参 IPage page = new Page<>(); page.setCurrent(healthManagerSearchVO.getCurrent()); page.setSize(healthManagerSearchVO.getSize()); page.setTotal(response.getHits().getHits().length); page.setPages((response.getHits().getHits().length + healthManagerSearchVO.getSize() - 1) / healthManagerSearchVO.getSize()); List records = new ArrayList<>(); for (SearchHit hit : response.getHits().getHits()) { Map sourceAsMap = hit.getSourceAsMap(); DoctorSearchResponseDTO doctorSearchResponseDTO = new DoctorSearchResponseDTO(); DoctorSearchResponseDTO newDTO = BeanUtil.fillBeanWithMap(sourceAsMap, doctorSearchResponseDTO, false); records.add(newDTO); } return page.setRecords(records); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)