From d747e1d366f8dde146e04b8575a36176f5f31230 Mon Sep 17 00:00:00 2001 From: GyeongSik Son <47748085+Son-GyeongSik@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:24:26 +0900 Subject: [PATCH] [SWM-387] Feat : supplement recommendation logic --- .../recommendation/RecommendationService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/m9d/sroom/recommendation/RecommendationService.java b/src/main/java/com/m9d/sroom/recommendation/RecommendationService.java index dc422ebf..bace30f2 100644 --- a/src/main/java/com/m9d/sroom/recommendation/RecommendationService.java +++ b/src/main/java/com/m9d/sroom/recommendation/RecommendationService.java @@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.stream.Collectors; @Slf4j @Service @@ -39,8 +40,8 @@ public Recommendations getRecommendations(Long memberId) { List generalRecommendLectureList = new ArrayList<>(); List channelRecommendLectureList = getRecommendsByChannel(memberId); - generalRecommendLectureList.addAll(getRecommendLectures(videoService.getTopRatedVideos(5))); - generalRecommendLectureList.addAll(getRecommendLectures(playlistService.getTopRatedPlaylists(5))); + generalRecommendLectureList.addAll(getRecommendLectures(videoService.getTopRatedVideos(10))); + generalRecommendLectureList.addAll(getRecommendLectures(playlistService.getTopRatedPlaylists(10))); Set enrolledLectureSet = lectureService.getEnrolledLectures(memberId); @@ -49,9 +50,13 @@ public Recommendations getRecommendations(Long memberId) { channelRecommendLectureList.removeIf(recommendLecture -> (recommendLecture.getLectureCode().equals(lectureCode))); } + Collections.shuffle(generalRecommendLectureList); + Collections.shuffle(channelRecommendLectureList); Recommendations recommendations = Recommendations.builder() .generalRecommendations(generalRecommendLectureList) - .channelRecommendations(channelRecommendLectureList) + .channelRecommendations(channelRecommendLectureList.stream() + .limit(20) + .collect(Collectors.toList())) .build(); return recommendations; @@ -59,12 +64,12 @@ public Recommendations getRecommendations(Long memberId) { public List getRecommendsByChannel(Long memberId) { - List recommendLecturesByChannel = new ArrayList<>(); + HashSet recommendLectureSetByChannel = new HashSet<>(); List channels = lectureService.getMostEnrolledChannels(memberId); - final int SELECT_BY_RANDOM_LIMIT = 1; - final int SELECT_BY_PUBLISH_DATE_LIMIT = 2; - final int SELECT_BY_VIEWED_LIMIT = 3; + final int SELECT_BY_RANDOM_LIMIT = 2; + final int SELECT_BY_PUBLISH_DATE_LIMIT = 3; + final int SELECT_BY_VIEWED_LIMIT = 5; for (String channelName : channels) { List lectures = new ArrayList<>(); @@ -78,10 +83,10 @@ public List getRecommendsByChannel(Long memberId) { lectures.addAll(videoRepository.getLatestOrderByChannel(channelName, SELECT_BY_PUBLISH_DATE_LIMIT)); lectures.addAll(playlistRepository.getLatestOrderByChannel(channelName, SELECT_BY_PUBLISH_DATE_LIMIT)); - recommendLecturesByChannel.addAll(getRecommendLectures(lectures)); + recommendLectureSetByChannel.addAll(getRecommendLectures(lectures)); } - return recommendLecturesByChannel; + return new ArrayList<>(recommendLectureSetByChannel); } public List getRecommendLectures(List lectures) {