-
Notifications
You must be signed in to change notification settings - Fork 0
MongoDB Atlas search 사용하도록 변경 #72
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
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
07fc951
hotfix: 중복 로그인 로직 원상복귀
elive7 9153923
[SCRUM-213] feat: mongodb 의존성 추가
elive7 b5a441e
[SCRUM-213] feat: mongodb에서 사용할 ArtistMongo 도메인 작성
elive7 c170186
[SCRUM-213] feat: 검색을 위한 searchArtistIdsByName 작성
elive7 07f8be5
[SCRUM-213] feat: 가수 검색 서비스 작성
elive7 5d45a08
[SCRUM-213] feat: 가수의 secondName, thirdName이 공백일 때도 필터
elive7 6a17b44
[SCRUM-213] feat: 가수의 secondName, thirdName이 공백일 때도 필터
elive7 7ed2b29
Merge branch 'SCRUM-213' of https://github.com/project-lyrics/api-ser…
elive7 8716f51
SCRUM-213] test: 가수 검색 성능 테스트 작성
elive7 21e64ac
[SCRUM-213] test: 검색에 필요한 repository 함수 추가 정의
elive7 c4d22cd
[SCRUM-213] feat: ArtistCommandService에 mongodb 삽입 삭제 로직 추가
elive7 6393f42
[SCRUM-213] feat: ArtistMongoCommandRepository 정의
elive7 aef4a84
[SCRUM-213] test: 테스트를 위해 ArtistFixture에 create 추가에
elive7 db3b1b9
[SCRUM-213] fix: elastic search 오류로 인해 곡 이름 검색 like로 회귀
elive7 e1ca5a3
[SCRUM-213] feat: 곡 검색을 위한 SongMongo 도메인 작성
elive7 b497d24
[SCRUM-213] feat: 곡 검색을 위한 SongMongoQueryRepository 작성
elive7 973300e
[SCRUM-213] feat: SongQueryService 내 searchSongs 수정
elive7 5f9b07f
[SCRUM-213] feat: SongMongoCommandRepository 및 Service 작성
elive7 7f48b2c
[SCRUM-213] feat: DummyDataInitializer 및 SongCollector 시에도 mongdb에 노래…
elive7 79fe056
[SCRUM-213] feat: mongodb<->mysql 간 주기적 동기화 로직 추가
elive7 153dd43
[SCRUM-213] feat: SongMongo에서 artistId 필드 삭제
elive7 ad3e105
[SCRUM-213] feat: SongCollector에 profile 추가
elive7 0c6607a
[SCRUM-213] refactor: 기본 mysql seacrch 함수 추가 및 리팩토링
elive7 b8b8741
[SCRUM-213] feat: Artist 검색 관련 성능 테스트 함수 작성
elive7 3120d15
[SCRUM-213] feat: 노래 검색 관련 성능 테스트 함수 작성
elive7 0c0eb6b
Merge branch 'SCRUM-213' of https://github.com/project-lyrics/api-ser…
elive7 895e33c
[SCRUM-213] feat: Artist 검색 관련 성능 테스트 함수 수정
elive7 d5871b4
[SCRUM-213] feat: local 환경에서 mongodb noop으로 분리될 수 있도록 분할 및 프로필 추가
elive7 4360963
[SCRUM-213] test: SongSearchPerformanceTest 에서 사용하지 않는 레포지토리 삭제
elive7 1eb1d70
[SCRUM-213] refactor: 함수 이름 변경
elive7 d60a49b
[SCRUM-213] refactor: MongoCommandRepository 내 함수 반환 타입&인자 수정
elive7 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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/projectlyrics/server/domain/artist/entity/ArtistMongo.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,32 @@ | ||
| package com.projectlyrics.server.domain.artist.entity; | ||
|
|
||
| import jakarta.persistence.Id; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
| import org.springframework.data.mongodb.core.mapping.Document; | ||
| import org.springframework.data.mongodb.core.mapping.Field; | ||
|
|
||
| @Document(collection = "artists") | ||
| public class ArtistMongo { | ||
| @Id | ||
| private final Long id; | ||
|
|
||
| @Field("search_names") | ||
| private final String searchNames; | ||
|
|
||
| private ArtistMongo(Long id, String searchNames) { | ||
| this.id = id; | ||
| this.searchNames = searchNames; | ||
| } | ||
|
|
||
| public static ArtistMongo of(Artist artist) { | ||
| String searchNames = Stream.of( | ||
| artist.getName(), | ||
| artist.getSecondName(), | ||
| artist.getThirdName()) | ||
| .filter(s -> s != null && !s.isBlank()) | ||
| .collect(Collectors.joining(" ")); | ||
| return new ArtistMongo(artist.getId(), searchNames); | ||
| } | ||
| } | ||
|
|
15 changes: 15 additions & 0 deletions
15
.../java/com/projectlyrics/server/domain/artist/repository/ArtistMongoCommandRepository.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,15 @@ | ||
| package com.projectlyrics.server.domain.artist.repository; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.entity.ArtistMongo; | ||
| import java.util.List; | ||
|
|
||
| public interface ArtistMongoCommandRepository { | ||
| ArtistMongo save(ArtistMongo artist); | ||
|
|
||
| List<ArtistMongo> saveAll(List<ArtistMongo> artists); | ||
|
|
||
| void delete(ArtistMongo artist); | ||
|
|
||
| void deleteAll(); | ||
| } | ||
|
|
7 changes: 7 additions & 0 deletions
7
...in/java/com/projectlyrics/server/domain/artist/repository/ArtistMongoQueryRepository.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,7 @@ | ||
| package com.projectlyrics.server.domain.artist.repository; | ||
|
|
||
| import com.projectlyrics.server.domain.common.dto.util.IdsWithHasNext; | ||
|
|
||
| public interface ArtistMongoQueryRepository { | ||
| IdsWithHasNext searchArtistIdsByName(String query, int offset, int limit); | ||
| } |
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
9 changes: 9 additions & 0 deletions
9
...com/projectlyrics/server/domain/artist/repository/impl/AritstMongoDelegateRepository.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,9 @@ | ||
| package com.projectlyrics.server.domain.artist.repository.impl; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.entity.ArtistMongo; | ||
| import org.springframework.data.mongodb.repository.MongoRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface AritstMongoDelegateRepository extends MongoRepository<ArtistMongo, Long> { | ||
| } |
36 changes: 36 additions & 0 deletions
36
.../projectlyrics/server/domain/artist/repository/impl/ArtistMongoCommandRepositoryImpl.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,36 @@ | ||
| package com.projectlyrics.server.domain.artist.repository.impl; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.entity.ArtistMongo; | ||
| import com.projectlyrics.server.domain.artist.repository.ArtistMongoCommandRepository; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @Profile({"dev", "prod"}) | ||
| @RequiredArgsConstructor | ||
| public class ArtistMongoCommandRepositoryImpl implements ArtistMongoCommandRepository { | ||
|
|
||
| private final AritstMongoDelegateRepository delegate; | ||
|
|
||
| @Override | ||
| public ArtistMongo save(ArtistMongo artist) { | ||
| return delegate.save(artist); | ||
| } | ||
|
|
||
| @Override | ||
| public List<ArtistMongo> saveAll(List<ArtistMongo> artists) { | ||
| return delegate.saveAll(artists); | ||
| } | ||
|
|
||
| @Override | ||
| public void delete(ArtistMongo artist) { | ||
| delegate.delete(artist); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAll() { | ||
| delegate.deleteAll(); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
...om/projectlyrics/server/domain/artist/repository/impl/ArtistMongoQueryRepositoryImpl.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,57 @@ | ||
| package com.projectlyrics.server.domain.artist.repository.impl; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.repository.ArtistMongoQueryRepository; | ||
| import com.projectlyrics.server.domain.common.dto.util.IdsWithHasNext; | ||
| import java.util.List; | ||
| import org.bson.Document; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.data.mongodb.core.MongoTemplate; | ||
| import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
| import org.springframework.data.mongodb.core.aggregation.AggregationOperation; | ||
| import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @Profile({"dev", "prod"}) | ||
| public class ArtistMongoQueryRepositoryImpl implements ArtistMongoQueryRepository { | ||
|
|
||
| private final MongoTemplate mongoTemplate; | ||
|
|
||
| public ArtistMongoQueryRepositoryImpl(MongoTemplate mongoTemplate) { | ||
| this.mongoTemplate = mongoTemplate; | ||
| } | ||
|
|
||
| public IdsWithHasNext searchArtistIdsByName(String query, int offset, int limit) { | ||
| // edgeGram autocomplete | ||
| AggregationOperation searchStage = context -> new Document("$search", | ||
| new Document("index", "artists_search_index") | ||
| .append("autocomplete", new Document() | ||
| .append("query", query) | ||
| .append("path", "search_names") | ||
| .append("tokenOrder", "any") | ||
| ) | ||
| ); | ||
|
|
||
| AggregationOperation projectStage = Aggregation.project("_id"); | ||
| AggregationOperation skipStage = Aggregation.skip(offset); | ||
| AggregationOperation limitStage = Aggregation.limit(limit + 1); | ||
|
|
||
| Aggregation aggregation = Aggregation.newAggregation(searchStage, projectStage, skipStage, limitStage); | ||
|
|
||
| AggregationResults<Document> results = | ||
| mongoTemplate.aggregate(aggregation, "artists", Document.class); | ||
|
|
||
| List<Long> ids = results.getMappedResults().stream() | ||
| .map(doc -> doc.get("_id", Long.class)) | ||
| .toList(); | ||
|
|
||
| boolean hasNext = ids.size() > limit; | ||
|
|
||
| if (hasNext) { | ||
| ids = ids.subList(0, limit); | ||
| } | ||
|
|
||
| return new IdsWithHasNext(ids, hasNext); | ||
| } | ||
| } | ||
|
|
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
31 changes: 31 additions & 0 deletions
31
.../projectlyrics/server/domain/artist/repository/noop/NoOpArtistMongoCommandRepository.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,31 @@ | ||
| package com.projectlyrics.server.domain.artist.repository.noop; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.entity.ArtistMongo; | ||
| import com.projectlyrics.server.domain.artist.repository.ArtistMongoCommandRepository; | ||
| import java.util.List; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @Profile({"!dev", "!prod"}) | ||
| public class NoOpArtistMongoCommandRepository implements ArtistMongoCommandRepository { | ||
|
|
||
| @Override | ||
| public ArtistMongo save(ArtistMongo artist) { | ||
| return artist; | ||
| } | ||
|
|
||
| @Override | ||
| public List<ArtistMongo> saveAll(List<ArtistMongo> artists) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public void delete(ArtistMongo artist) { | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAll() { | ||
| } | ||
| } | ||
|
|
16 changes: 16 additions & 0 deletions
16
...om/projectlyrics/server/domain/artist/repository/noop/NoOpArtistMongoQueryRepository.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,16 @@ | ||
| package com.projectlyrics.server.domain.artist.repository.noop; | ||
|
|
||
| import com.projectlyrics.server.domain.artist.repository.ArtistMongoQueryRepository; | ||
| import com.projectlyrics.server.domain.common.dto.util.IdsWithHasNext; | ||
| import java.util.List; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @Profile({"!dev", "!prod"}) | ||
| public class NoOpArtistMongoQueryRepository implements ArtistMongoQueryRepository { | ||
| @Override | ||
| public IdsWithHasNext searchArtistIdsByName(String query, int offset, int limit) { | ||
| return new IdsWithHasNext(List.of(), false); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.