Search in sources :

Example 1 with StudylogDocumentResponse

use of wooteco.prolog.studylog.application.dto.StudylogDocumentResponse in project prolog by woowacourse.

the class StudylogDocumentService method findBySearchKeyword.

@Override
public StudylogDocumentResponse findBySearchKeyword(String keyword, List<Long> tags, List<Long> missions, List<Long> levels, List<String> usernames, LocalDate start, LocalDate end, Pageable pageable) {
    final Query query = StudylogDocumentQueryBuilder.makeQuery(preprocess(keyword), tags, missions, levels, usernames, start, end, pageable);
    // Query 결과를 ES에서 조회한다.
    final SearchHits<StudylogDocument> searchHits = elasticsearchRestTemplate.search(query, StudylogDocument.class, IndexCoordinates.of("studylog-document"));
    // 조회된 SearchHits를 페이징할 수 있는 SearchPage로 변경한다.
    final SearchPage<StudylogDocument> searchPages = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
    final List<Long> studylogIds = searchPages.stream().map(searchPage -> searchPage.getContent().getId()).collect(toList());
    return StudylogDocumentResponse.of(studylogIds, searchPages.getTotalElements(), searchPages.getTotalPages(), searchPages.getNumber());
}
Also used : IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) SearchHits(org.springframework.data.elasticsearch.core.SearchHits) Query(org.springframework.data.elasticsearch.core.query.Query) SearchPage(org.springframework.data.elasticsearch.core.SearchPage) Profile(org.springframework.context.annotation.Profile) StudylogDocumentRepository(wooteco.prolog.studylog.domain.repository.StudylogDocumentRepository) StudylogDocumentResponse(wooteco.prolog.studylog.application.dto.StudylogDocumentResponse) ElasticsearchRestTemplate(org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate) SearchHitSupport(org.springframework.data.elasticsearch.core.SearchHitSupport) StudylogDocumentQueryBuilder(wooteco.prolog.studylog.domain.StudylogDocumentQueryBuilder) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument) Pageable(org.springframework.data.domain.Pageable) StudylogRepository(wooteco.prolog.studylog.domain.repository.StudylogRepository) Query(org.springframework.data.elasticsearch.core.query.Query) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument)

Example 2 with StudylogDocumentResponse

use of wooteco.prolog.studylog.application.dto.StudylogDocumentResponse in project prolog by woowacourse.

the class StudylogService method findStudylogs.

public StudylogsResponse findStudylogs(StudylogsSearchRequest request, Long memberId) {
    if (Objects.nonNull(request.getIds())) {
        Pageable pageable = request.getPageable();
        List<Long> ids = request.getIds();
        Page<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdAsc(ids, pageable);
        return StudylogsResponse.of(studylogs, memberId);
    }
    if (request.getKeyword() == null || request.getKeyword().isEmpty()) {
        return findStudylogsWithoutKeyword(request.getSessions(), request.getMissions(), request.getTags(), request.getUsernames(), request.getMembers(), request.getStartDate(), request.getEndDate(), request.getPageable(), memberId);
    }
    final StudylogDocumentResponse response = studylogDocumentService.findBySearchKeyword(request.getKeyword(), request.getTags(), request.getMissions(), request.getSessions(), request.getUsernames(), request.getStartDate(), request.getEndDate(), request.getPageable());
    final List<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdDesc(response.getStudylogIds());
    return StudylogsResponse.of(studylogs, response.getTotalSize(), response.getTotalPage(), response.getCurrPage(), memberId);
}
Also used : Pageable(org.springframework.data.domain.Pageable) StudylogDocumentResponse(wooteco.prolog.studylog.application.dto.StudylogDocumentResponse) Studylog(wooteco.prolog.studylog.domain.Studylog)

Aggregations

Pageable (org.springframework.data.domain.Pageable)2 StudylogDocumentResponse (wooteco.prolog.studylog.application.dto.StudylogDocumentResponse)2 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Profile (org.springframework.context.annotation.Profile)1 ElasticsearchRestTemplate (org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate)1 SearchHitSupport (org.springframework.data.elasticsearch.core.SearchHitSupport)1 SearchHits (org.springframework.data.elasticsearch.core.SearchHits)1 SearchPage (org.springframework.data.elasticsearch.core.SearchPage)1 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)1 Query (org.springframework.data.elasticsearch.core.query.Query)1 Service (org.springframework.stereotype.Service)1 Studylog (wooteco.prolog.studylog.domain.Studylog)1 StudylogDocument (wooteco.prolog.studylog.domain.StudylogDocument)1 StudylogDocumentQueryBuilder (wooteco.prolog.studylog.domain.StudylogDocumentQueryBuilder)1 StudylogDocumentRepository (wooteco.prolog.studylog.domain.repository.StudylogDocumentRepository)1 StudylogRepository (wooteco.prolog.studylog.domain.repository.StudylogRepository)1