-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feature]검색 기능 추가
- Loading branch information
Showing
7 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
backend/src/main/java/moadong/club/repository/ClubKeywordSearchRepository.java
This file contains 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 moadong.club.repository; | ||
|
||
import moadong.club.payload.dto.ClubSearchResult; | ||
|
||
import java.util.List; | ||
|
||
public interface ClubKeywordSearchRepository { | ||
List<ClubSearchResult> searchResult(String keyword); | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/moadong/club/repository/ClubKeywordSearchRepositoryImpl.java
This file contains 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,44 @@ | ||
package moadong.club.repository; | ||
|
||
import lombok.AllArgsConstructor; | ||
import moadong.club.payload.dto.ClubSearchResult; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@AllArgsConstructor | ||
public class ClubKeywordSearchRepositoryImpl implements ClubKeywordSearchRepository { | ||
private final MongoTemplate mongoTemplate; | ||
|
||
@Override | ||
public List<ClubSearchResult> searchResult(String keyword) { | ||
Aggregation aggregation = Aggregation.newAggregation( | ||
Aggregation.lookup("club_information", "_id", "clubId", "club_info"), | ||
Aggregation.lookup("club_tags", "_id", "clubId", "club_tags"), | ||
Aggregation.match(new Criteria().orOperator( | ||
Criteria.where("name").regex(keyword, "i"), | ||
Criteria.where("club_info.description").regex(keyword, "i"), | ||
Criteria.where("club_tags.tag").regex(keyword, "i") | ||
)), | ||
Aggregation.unwind("club_tags", true), | ||
Aggregation.group("_id") | ||
.first("name").as("name") | ||
.first("state").as("state") | ||
.first("classification").as("classification") | ||
.first("division").as("division") | ||
.first("club_info").as("club_info") | ||
.push("club_tags.tag").as("tags"), | ||
Aggregation.project("name", "state", "classification", "division") | ||
.and("club_info.introduction").as("introduction") | ||
.and("club_info.logo").as("logo") | ||
.and("tags").as("tags") | ||
); | ||
AggregationResults<ClubSearchResult> results = mongoTemplate.aggregate(aggregation, "club", ClubSearchResult.class); | ||
return results.getMappedResults(); | ||
} | ||
} |
This file contains 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
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/moadong/club/service/ClubSearchService.java
This file contains 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,22 @@ | ||
package moadong.club.service; | ||
|
||
import lombok.AllArgsConstructor; | ||
import moadong.club.payload.dto.ClubSearchResult; | ||
import moadong.club.payload.response.ClubSearchResponse; | ||
import moadong.club.repository.ClubKeywordSearchRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class ClubSearchService { | ||
private final ClubKeywordSearchRepository clubKeywordSearchRepository; | ||
public ClubSearchResponse searchClubsByKeyword(String keyword) { | ||
List<ClubSearchResult> clubSearchResults = clubKeywordSearchRepository.searchResult(keyword); | ||
|
||
return ClubSearchResponse.builder() | ||
.clubs(clubSearchResults) | ||
.build(); | ||
} | ||
} |