Java Code Examples for org.springframework.data.mongodb.core.aggregation.Aggregation#match()
The following examples show how to use
org.springframework.data.mongodb.core.aggregation.Aggregation#match() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryOnListTest.java From jakduk-api with MIT License | 10 votes |
@Test public void findById() { ArrayList<ObjectId> arrTemp = new ArrayList<ObjectId>(); arrTemp.add(new ObjectId("54c4df893d96600d7f55a048")); arrTemp.add(new ObjectId("54c4e4833d96deb0f8592907")); AggregationOperation match = Aggregation.match(Criteria.where("_id").in(arrTemp)); //AggregationOperation group = Aggregation.group("article").count().as("count"); AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id"); //AggregationOperation limit = Aggregation.limit(Constants.BOARD_LINE_NUMBER); Aggregation aggregation = Aggregation.newAggregation(match, /*group, */ sort /*, limit*/); AggregationResults<Gallery> results = mongoTemplate.aggregate(aggregation, "gallery", Gallery.class); System.out.println("findOneById=" + results.getMappedResults()); }
Example 2
Source File: ArticleCommentRepositoryImpl.java From jakduk-api with MIT License | 8 votes |
/** * boardItem의 boardId 기준 이상의 댓글 수를 가져온다 * * @param boardId 기준이 되는 boardItem의 boardId */ @Override public List<CommonCount> findCommentsCountGreaterThanBoardIdAndBoard(ObjectId boardId, Constants.BOARD_TYPE board) { AggregationOperation match1 = Aggregation.match(Criteria.where("article._id").gt(boardId).and("article.board").is(board.name())); AggregationOperation group = Aggregation.group("article").count().as("count"); AggregationOperation sort = Aggregation.sort(Sort.Direction.DESC, "count"); //AggregationOperation limit = Aggregation.limit(Constants.BOARD_TOP_LIMIT); Aggregation aggregation = Aggregation.newAggregation(match1, group, sort/*, limit*/); AggregationResults<CommonCount> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, CommonCount.class); return results.getMappedResults(); }
Example 3
Source File: JakdukDAO.java From jakduk-api with MIT License | 7 votes |
public List<SupporterCount> getSupportFCCount(String language) { AggregationOperation match = Aggregation.match(Criteria.where("supportFC").exists(true)); AggregationOperation group = Aggregation.group("supportFC").count().as("count"); AggregationOperation project = Aggregation.project("count").and("_id").as("supportFC"); AggregationOperation sort = Aggregation.sort(Direction.DESC, "count"); Aggregation aggregation = Aggregation.newAggregation(match, group, project, sort); AggregationResults<SupporterCount> results = mongoTemplate.aggregate(aggregation, "user", SupporterCount.class); List<SupporterCount> users = results.getMappedResults(); for (SupporterCount supporterCount : users) { supporterCount.getSupportFC().getNames().removeIf(fcName -> !fcName.getLanguage().equals(language)); } return users; }
Example 4
Source File: ArticleCommentRepositoryImpl.java From jakduk-api with MIT License | 7 votes |
/** * 게시물 ID 에 해당하는 댓글 수를 가져온다. */ @Override public List<CommonCount> findCommentsCountByIds(List<ObjectId> ids) { AggregationOperation match = Aggregation.match(Criteria.where("article._id").in(ids)); AggregationOperation group = Aggregation.group("article").count().as("count"); //AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id"); //AggregationOperation limit = Aggregation.limit(Constants.BOARD_LINE_NUMBER); Aggregation aggregation = Aggregation.newAggregation(match, group/*, sort, limit*/); AggregationResults<CommonCount> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, CommonCount.class); return results.getMappedResults(); }
Example 5
Source File: JakdukDAO.java From jakduk-api with MIT License | 6 votes |
public List<JakduComment> getJakduComments(String jakduScheduleId, ObjectId commentId) { AggregationOperation match1 = Aggregation.match(Criteria.where("jakduScheduleId").is(jakduScheduleId)); AggregationOperation match2 = Aggregation.match(Criteria.where("_id").gt(commentId)); AggregationOperation sort = Aggregation.sort(Direction.ASC, "_id"); AggregationOperation limit = Aggregation.limit(Constants.COMMENT_MAX_LIMIT); Aggregation aggregation; if (Objects.nonNull(commentId)) { aggregation = Aggregation.newAggregation(match1, match2, sort, limit); } else { aggregation = Aggregation.newAggregation(match1, sort, limit); } AggregationResults<JakduComment> results = mongoTemplate.aggregate(aggregation, "jakduComment", JakduComment.class); List<JakduComment> comments = results.getMappedResults(); return comments; }
Example 6
Source File: ArticleCommentRepositoryImpl.java From jakduk-api with MIT License | 6 votes |
/** * 기준 ArticleComment ID 이상의 ArticleComment 목록을 가져온다. */ @Override public List<ArticleComment> findCommentsGreaterThanId(ObjectId objectId, Integer limit) { AggregationOperation match1 = Aggregation.match(Criteria.where("_id").gt(objectId)); AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC, "_id"); AggregationOperation limit1 = Aggregation.limit(limit); Aggregation aggregation; if (! ObjectUtils.isEmpty(objectId)) { aggregation = Aggregation.newAggregation(match1, sort, limit1); } else { aggregation = Aggregation.newAggregation(sort, limit1); } AggregationResults<ArticleComment> results = mongoTemplate.aggregate(aggregation, Constants.COLLECTION_ARTICLE_COMMENT, ArticleComment.class); return results.getMappedResults(); }
Example 7
Source File: UserInfoServiceImpl.java From ExecDashboard with Apache License 2.0 | 5 votes |
@Override public List<String> getFrequentExecutives() { List<String> executives = new LinkedList<>(); try { Map<String, Integer> resultsMap = new HashMap<>(); Map<String, Integer> resultsMapSorted = new LinkedHashMap<>(); List<String> views = new ArrayList<>(); views.add(PORTFOLIO); views.add(PORTFOLIOMETRIC); GroupOperation groupByExecutiveViewId = Aggregation.group(EXECUTIVEVIEWID).count().as(TOTAL); MatchOperation filter = Aggregation.match(new Criteria(VIEW).in(views).andOperator( Criteria.where(TIMESTAMP).gte(getTimeStamp(30)), Criteria.where(EXECUTIVEVIEWID).ne(null))); Aggregation aggregation = Aggregation.newAggregation(filter, groupByExecutiveViewId); AggregationResults<DBObject> temp = mongoTemplate.aggregate(aggregation, TRACKVIEWS, DBObject.class); if (temp != null) { List<DBObject> results = temp.getMappedResults(); if (results != null && !results.isEmpty()) { for (DBObject object : results) { if (object.get(FIRSTORDER) != null) { String id = object.get(FIRSTORDER).toString(); Integer total = (Integer) object.get(TOTAL); resultsMap.put(id, total); } } resultsMap.entrySet().stream().sorted(Map.Entry.<String, Integer> comparingByValue().reversed()) .forEachOrdered(x -> resultsMapSorted.put(x.getKey(), x.getValue())); resultsMapSorted.forEach((eid, v) -> { ExecutiveSummaryList executive = executiveSummaryListRepository.findByEid(eid); if (executive != null) { executives.add(executive.getFirstName() + ", " + executive.getLastName()); } }); } } } catch (Exception e) { LOG.error("User Tracking, getFrequentExecutives :: " + e); } return executives; }
Example 8
Source File: UserInfoServiceImpl.java From ExecDashboard with Apache License 2.0 | 5 votes |
@Override public List<String> getFrequentApplications() { List<String> applications = new LinkedList<>(); try { Map<String, Integer> resultsMap = new HashMap<>(); Map<String, Integer> resultsMapSorted = new LinkedHashMap<>(); List<String> views = new ArrayList<>(); views.add(PRODUCTMETRIC); views.add(PRODUCT); GroupOperation groupByApplicationViewId = Aggregation.group(APPLICATIONVIEWID).count().as(TOTAL); MatchOperation filter = Aggregation.match(new Criteria(VIEW).in(views).andOperator( Criteria.where(TIMESTAMP).gte(getTimeStamp(30)), Criteria.where(APPLICATIONVIEWID).ne(null))); Aggregation aggregation = Aggregation.newAggregation(filter, groupByApplicationViewId); AggregationResults<DBObject> temp = mongoTemplate.aggregate(aggregation, TRACKVIEWS, DBObject.class); if (temp != null) { List<DBObject> results = temp.getMappedResults(); if (results != null && !results.isEmpty()) { for (DBObject object : results) { if (object.get(FIRSTORDER) != null) { String id = object.get(FIRSTORDER).toString(); Integer total = (Integer) object.get(TOTAL); resultsMap.put(id, total); } } resultsMap.entrySet().stream().sorted(Map.Entry.<String, Integer> comparingByValue().reversed()) .forEachOrdered(x -> resultsMapSorted.put(x.getKey(), x.getValue())); resultsMapSorted.forEach((appId, v) -> { ApplicationDetails app = applicationDetailsRepository.findByAppId(appId); if (app != null) { applications.add(app.getAppName() + " - " + app.getLob()); } }); } } } catch (Exception e) { LOG.error("User Tracking, getFrequentApplications :: " + e); } return applications; }
Example 9
Source File: UserInfoServiceImpl.java From ExecDashboard with Apache License 2.0 | 5 votes |
@Override public List<String> getFrequentCards() { List<String> metrics = new LinkedList<>(); try { Map<String, Integer> resultsMap = new HashMap<>(); Map<String, Integer> resultsMapSorted = new LinkedHashMap<>(); List<String> views = new ArrayList<>(); views.add(PRODUCTMETRIC); views.add(PORTFOLIOMETRIC); GroupOperation groupByApplicationViewId = Aggregation.group(METRICSNAME).count().as(TOTAL); MatchOperation filter = Aggregation.match(new Criteria(VIEW).in(views).andOperator( Criteria.where(TIMESTAMP).gte(getTimeStamp(30)), Criteria.where(METRICSNAME).ne(null))); Aggregation aggregation = Aggregation.newAggregation(filter, groupByApplicationViewId); AggregationResults<DBObject> temp = mongoTemplate.aggregate(aggregation, TRACKVIEWS, DBObject.class); if (temp != null) { List<DBObject> results = temp.getMappedResults(); if (results != null && !results.isEmpty()) { for (DBObject object : results) { if (object.get(ID) != null) { String id = object.get(ID).toString(); Integer total = (Integer) object.get(TOTAL); resultsMap.put(id, total); } } resultsMap.entrySet().stream().sorted(Map.Entry.<String, Integer> comparingByValue().reversed()) .forEachOrdered(x -> resultsMapSorted.put(x.getKey(), x.getValue())); resultsMapSorted.forEach((k, v) -> metrics.add(k)); } } } catch (Exception e) { LOG.error("User Tracking, getFrequentCards :: " + e); } return metrics; }
Example 10
Source File: AuthorServiceImpl.java From biliob_backend with MIT License | 5 votes |
private MatchOperation getAggregateMatch(int days, Long mid) { if (days == -1) { return Aggregation.match(Criteria.where("mid").is(mid)); } else { Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, -days); return Aggregation.match(Criteria.where("mid").is(mid).and("datetime").gt(c.getTime())); } }
Example 11
Source File: AuthorGroupServiceImpl.java From biliob_backend with MIT License | 5 votes |
@Override public List<AuthorGroup> listAuthorList(String keyword, Long page, Integer pageSize) { MatchOperation match; if (!"".equals(keyword)) { match = Aggregation.match(new Criteria().orOperator(Criteria.where("name").regex(keyword, "i"), Criteria.where("desc").regex(keyword, "i"), Criteria.where("tagList").is(keyword))); } else { match = Aggregation.match(new Criteria()); } logger.info("{} {}", keyword, page); return this.listAuthorList(match, page, pageSize); }