-
Notifications
You must be signed in to change notification settings - Fork 1
[BUILD FAIL] [BUILD FAIL] Feature/137 봉사활동 모집글, 커뮤니티 게시글 검색 조회 (elastic search) #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
98b3ae3
feature(search): elasticsearch 의존성 추가
ayoung-dev 65bc207
feature(search): elasticsearch document, repository 생성
ayoung-dev ca23f96
feature(search): repository에 elasticsearch 관련 메서드 추가
ayoung-dev 28e2990
feature(search): service 추가
ayoung-dev ea3d75b
feature(search): controller 키워드 검색 추가
ayoung-dev 53533f1
feature(search): elasticsearch 저장 스케쥴러 추가
ayoung-dev 27994bb
feature(search): elasticsearch config 추가
ayoung-dev 0a99d88
feature(search): community 게시글 fixture 추가
ayoung-dev aa4c16d
test(search): community 게시글 검색 테스트 추가
ayoung-dev 4d59d93
test(search): recruit 모집글 검색 테스트 추가
ayoung-dev 3fa8e8e
test(search): import 경로 수정
ayoung-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/somemore/community/domain/CommunityBoardDocument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.somemore.community.domain; | ||
|
|
||
| import jakarta.persistence.Id; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import org.springframework.data.elasticsearch.annotations.Document; | ||
| import org.springframework.data.elasticsearch.annotations.Field; | ||
| import org.springframework.data.elasticsearch.annotations.FieldType; | ||
|
|
||
| @Getter | ||
| @Document(indexName = "community_board") | ||
| public class CommunityBoardDocument { | ||
|
|
||
| @Id | ||
| private Long id; | ||
|
|
||
| @Field(type = FieldType.Text, analyzer = "nori_analyzer") | ||
| private String title; | ||
|
|
||
| @Field(type = FieldType.Text, analyzer = "nori_analyzer") | ||
| private String content; | ||
|
|
||
| @Builder | ||
| public CommunityBoardDocument(Long id, String title, String content) { | ||
| this.id = id; | ||
| this.title = title; | ||
| this.content = content; | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/somemore/community/repository/board/CommunityBoardDocumentRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.somemore.community.repository.board; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoardDocument; | ||
| import org.springframework.data.elasticsearch.annotations.Query; | ||
| import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CommunityBoardDocumentRepository extends ElasticsearchRepository<CommunityBoardDocument, Long> { | ||
| @Query("{\"multi_match\": {\"query\": \"?0\", \"fields\": [\"title\", \"content\"]}}") | ||
| List<CommunityBoardDocument> findIdsByTitleOrContentContaining(String keyword); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/somemore/community/scheduler/CommunityScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.somemore.community.scheduler; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase; | ||
| import com.somemore.community.usecase.board.CommunityBoardQueryUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CommunityScheduler { | ||
|
|
||
| private final CommunityBoardQueryUseCase communityBoardQueryUseCase; | ||
| private final CommunityBoardDocumentUseCase communityBoardDocumentUseCase; | ||
|
|
||
|
|
||
| @Scheduled(cron = "10 * * * * *") | ||
| public void updateCommunityBoardDocuments() { | ||
| List<CommunityBoard> communityBoards = communityBoardQueryUseCase.getAllCommunityBoards(); | ||
| communityBoardDocumentUseCase.saveCommunityBoardDocuments(communityBoards); | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
src/main/java/com/somemore/community/service/board/CommunityBoardDocumentService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.somemore.community.service.board; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.dto.response.CommunityBoardResponseDto; | ||
| import com.somemore.community.repository.board.CommunityBoardRepository; | ||
| import com.somemore.community.repository.mapper.CommunityBoardView; | ||
| import com.somemore.community.usecase.board.CommunityBoardDocumentUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class CommunityBoardDocumentService implements CommunityBoardDocumentUseCase { | ||
|
|
||
| private final CommunityBoardRepository communityBoardRepository; | ||
| private static final int PAGE_SIZE = 10; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| @Override | ||
| public Page<CommunityBoardResponseDto> getCommunityBoardBySearch(String keyword, int page) { | ||
| Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
| Page<CommunityBoardView> boards = communityBoardRepository.findByCommunityBoardsContaining(keyword, pageable); | ||
| return boards.map(CommunityBoardResponseDto::from); | ||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void saveCommunityBoardDocuments(List<CommunityBoard> communityBoards) { | ||
| communityBoardRepository.saveDocuments(communityBoards); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/somemore/community/usecase/board/CommunityBoardDocumentUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.somemore.community.usecase.board; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.dto.response.CommunityBoardResponseDto; | ||
| import org.springframework.data.domain.Page; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CommunityBoardDocumentUseCase { | ||
| Page<CommunityBoardResponseDto> getCommunityBoardBySearch(String keyword, int page); | ||
| void saveCommunityBoardDocuments(List<CommunityBoard> communityBoards); | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/somemore/community/usecase/board/CommunityBoardQueryUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| package com.somemore.community.usecase.board; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.dto.response.CommunityBoardDetailResponseDto; | ||
| import com.somemore.community.dto.response.CommunityBoardResponseDto; | ||
| import org.springframework.data.domain.Page; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public interface CommunityBoardQueryUseCase { | ||
| Page<CommunityBoardResponseDto> getCommunityBoards(int page); | ||
| Page<CommunityBoardResponseDto> getCommunityBoardsByWriterId(UUID writerId, int page); | ||
| CommunityBoardDetailResponseDto getCommunityBoardDetail(Long id); | ||
| List<CommunityBoard> getAllCommunityBoards(); | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/somemore/global/configure/ElasticsearchConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.somemore.global.configure; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.elasticsearch.client.ClientConfiguration; | ||
| import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration; | ||
|
|
||
| @Configuration | ||
| public class ElasticsearchConfig extends ElasticsearchConfiguration { | ||
| @Value("${elastic.search.uris}") | ||
| private String uri; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uris 리스트인가요? 아니라면 url가 더 나은것 같습니다.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정했습니다! |
||
| @Value("${elastic.search.username}") | ||
| private String username; | ||
| @Value("${elastic.search.password}") | ||
| private String password; | ||
|
|
||
| @Override | ||
| public ClientConfiguration clientConfiguration() { | ||
| return ClientConfiguration.builder() | ||
| .connectedTo(uri) | ||
| .withBasicAuth(username, password) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간격이 타이트 한 것 같습니다 제 생각엔 데이터 최신화를 위한 스케줄러 같은데 맞나요?
맞다면 getAll Community Boards라 부하가 클 거 같다는 생각이 듭니다
새벽에 한번 최신화를 시키고 사이에 벌어지는 업데이트들은
logstash로 저희 RDB를 체크하는게 어떨까요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 자정으로 수정하겠습니다