Search in sources :

Example 1 with PageRequest

use of com.topcom.cms.common.page.PageRequest 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)

Example 2 with PageRequest

use of com.topcom.cms.common.page.PageRequest in project topcom-cloud by 545314690.

the class StaffSentimentController method searchOneStaff.

// 后期改用多线程查询,临时单线程查询
private StaffSentiment searchOneStaff(Staff staff, StaffSentimentRequest request) {
    StaffSentiment staffSentiment = new StaffSentiment();
    staffSentiment.setId(String.valueOf(staff.getId()));
    staffSentiment.setStaff(staff.toMap());
    BoolQueryRequest boolRequest = new BoolQueryRequest();
    boolRequest.setDate(request.getDate());
    boolRequest.setGroupName("nlp.sentiment.label");
    boolRequest.setKeyword(new Keyword(staff.getExpression()));
    PageRequest page = new PageRequest(1, 10);
    page.setOrders(request.getSortBy());
    boolRequest.setPage(page);
    boolRequest.setFiled(request.getFiled());
    boolRequest.setType(request.getArticleType());
    // 情感值
    Map kvMap = KV.kvList2Map(esManager.filterAndGroupBy(boolRequest));
    staffSentiment.setNEG((Long) (kvMap.get("NEG") == null ? 0 : kvMap.get("NEG")));
    staffSentiment.setNEU((Long) (kvMap.get("NEU") == null ? 0 : kvMap.get("NEU")));
    staffSentiment.setPOS((Long) (kvMap.get("POS") == null ? 0 : kvMap.get("POS")));
    // 总数 以及条新闻,最新?还是最负面?
    Page articlePage = esManager.findByMustShouldDateInType(boolRequest);
    if (articlePage.getTotalElements() > 0) {
        staffSentiment.setArticle((Map) articlePage.getContent().get(0));
        staffSentiment.setTotal(articlePage.getTotalElements());
        Long time = Long.valueOf(((Map) articlePage.getContent().get(0)).get("pubTime").toString());
        staffSentiment.setNewsDate(new Date(time));
    }
    return staffSentiment;
}
Also used : BoolQueryRequest(com.topcom.cms.es.vo.BoolQueryRequest) PageRequest(com.topcom.cms.common.page.PageRequest) Keyword(com.topcom.cms.es.vo.Keyword) StaffSentiment(com.topcom.cms.yuqing.domain.StaffSentiment) Page(org.springframework.data.domain.Page) Map(java.util.Map) Date(java.util.Date)

Example 3 with PageRequest

use of com.topcom.cms.common.page.PageRequest in project topcom-cloud by 545314690.

the class DescriptionManagerImpl method specialOutline.

@Override
public Object specialOutline(BoolQueryRequest boolQueryRequest) {
    boolQueryRequest.setPage(new PageRequest(1, 1));
    JSONObject jsonObject = new JSONObject();
    Page page = allESDataService.findByMustShouldDateInType(boolQueryRequest);
    jsonObject.put("monthCount", page.getTotalElements());
    jsonObject.put("maxType", getMaxType(boolQueryRequest, "type"));
    jsonObject.put("label", getMaxType(boolQueryRequest, "nlp.sentiment.label"));
    boolQueryRequest.setType("news");
    jsonObject.put("maxSite", getMaxType(boolQueryRequest, "site"));
    jsonObject.put("maxTitle", getMaxType(boolQueryRequest, "title.raw"));
    return jsonObject;
}
Also used : PageRequest(com.topcom.cms.common.page.PageRequest) JSONObject(net.sf.json.JSONObject) Page(org.springframework.data.domain.Page)

Example 4 with PageRequest

use of com.topcom.cms.common.page.PageRequest in project topcom-cloud by 545314690.

the class DescriptionManagerImpl method monthLyOutline.

@Override
public Object monthLyOutline(BoolQueryRequest boolQueryRequest) {
    boolQueryRequest.setPage(new PageRequest(1, 1));
    JSONObject jsonObject = new JSONObject();
    Page page = allESDataService.findByMustShouldDateInType(boolQueryRequest);
    jsonObject.put("monthCount", page.getTotalElements());
    jsonObject.put("mom", getmom(boolQueryRequest, "month"));
    jsonObject.put("maxSite", getMaxType(boolQueryRequest, "site"));
    jsonObject.put("maxType", getMaxType(boolQueryRequest, "type"));
    jsonObject.put("compare", compareWithLastMonthEverySite(boolQueryRequest, "month"));
    jsonObject.put("label", getMaxType(boolQueryRequest, "nlp.sentiment.label"));
    return jsonObject;
}
Also used : PageRequest(com.topcom.cms.common.page.PageRequest) JSONObject(net.sf.json.JSONObject) Page(org.springframework.data.domain.Page)

Example 5 with PageRequest

use of com.topcom.cms.common.page.PageRequest in project topcom-cloud by 545314690.

the class WarningManagerImpl method getSubjectWarningInfo.

@Deprecated
@Override
public Page<News> getSubjectWarningInfo(CustomSubject subject, int pageNum, int limit) {
    WarningTask warning = subject.getWarning();
    if (warning == null) {
        return new PageImpl<News>(new ArrayList<News>());
    }
    BoolQueryRequest request = new BoolQueryRequest();
    request.setType(null);
    request.setFiled(null);
    request.setKeyword(new Keyword(subject.getMustWord(), subject.getShouldWord(), subject.getMustNotWord()));
    // 本次预警时间
    Date thisWarningDate = new Date();
    // 上次预警时间
    Date lastWarningDate = warning.getLastWarningDate();
    if (lastWarningDate == null) {
        lastWarningDate = subject.getStartDate();
    }
    request.setDate(new DateParam(DateUtil.dateToString(lastWarningDate), DateUtil.dateToString(thisWarningDate)));
    request.setPage(new PageRequest(pageNum, limit, new Order(Sort.Direction.DESC, "pubTime")));
    List<KV> kvList = new ArrayList<>();
    // 媒体类型
    String[] type = warning.getType();
    if (type != null && type.length > 0) {
        kvList.add(new KV("type", type));
    }
    String[] sentimentLabel = warning.getSentimentLabel();
    // 情感类型
    if (sentimentLabel != null && sentimentLabel.length != 0) {
        kvList.add(new KV("nlp.sentiment.label", sentimentLabel));
    }
    request.setSearchKv(kvList);
    final Page page = newsService.findByMustShouldDateInType(request);
    return page;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Order(com.topcom.cms.common.page.Order) BoolQueryRequest(com.topcom.cms.es.vo.BoolQueryRequest) Keyword(com.topcom.cms.es.vo.Keyword) ArrayList(java.util.ArrayList) Page(org.springframework.data.domain.Page) KV(com.topcom.cms.es.vo.KV) Date(java.util.Date) PageRequest(com.topcom.cms.common.page.PageRequest) News(com.topcom.cms.data.domain.News) WarningTask(com.topcom.cms.yuqing.domain.WarningTask) DateParam(com.topcom.cms.common.page.DateParam)

Aggregations

PageRequest (com.topcom.cms.common.page.PageRequest)7 Page (org.springframework.data.domain.Page)6 Date (java.util.Date)4 DateParam (com.topcom.cms.common.page.DateParam)3 Order (com.topcom.cms.common.page.Order)3 BoolQueryRequest (com.topcom.cms.es.vo.BoolQueryRequest)3 Keyword (com.topcom.cms.es.vo.Keyword)3 JSONObject (net.sf.json.JSONObject)3 KV (com.topcom.cms.es.vo.KV)2 ArrayList (java.util.ArrayList)2 PageImpl (org.springframework.data.domain.PageImpl)2 News (com.topcom.cms.data.domain.News)1 StaffSentiment (com.topcom.cms.yuqing.domain.StaffSentiment)1 WarningTask (com.topcom.cms.yuqing.domain.WarningTask)1 QueryWord (com.topcom.yzswf.util.QueryWord)1 ESQueryBuilderConstructor (com.topcom.yzswf.util.es.ESQueryBuilderConstructor)1 ESQueryBuilders (com.topcom.yzswf.util.es.ESQueryBuilders)1 Map (java.util.Map)1 Sort (org.springframework.data.domain.Sort)1