Skip to content

Commit

Permalink
Merge pull request #23 from khu-bigdata-project-team-5/feat/1
Browse files Browse the repository at this point in the history
๐Ÿš‘ [Hotfix] ํ‚ค์›Œ๋“œ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ ์‹œ, topword ๊ธฐ์ค€์œผ๋กœ ๊ฒ€์ƒ‰ ๋กœ์ง ์ถ”๊ฐ€
  • Loading branch information
yxhwxn authored Jun 13, 2024
2 parents ea6c9b4 + 83e2c7b commit 9b092d3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
24 changes: 19 additions & 5 deletions src/main/java/khu/bigdata/infou/business/LectureConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import khu.bigdata.infou.web.dto.LectureResponseDTO;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LectureConverter {
Expand Down Expand Up @@ -37,7 +38,7 @@ public static LectureResponseDTO.CategoryRecommendLectureDto toCategoryRecommend


// ํ‚ค์›Œ๋“œ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ
public static LectureResponseDTO.KeywordRecommendLectureInfo toKeywordRecommendLectureInfo(LectureUdemy lectureUdemy) {
public static LectureResponseDTO.KeywordRecommendLectureInfo toKeywordRecommendLectureInfo(LectureUdemy lectureUdemy, LectureTag lectureTag) {

return LectureResponseDTO.KeywordRecommendLectureInfo.builder()
.lectureId(lectureUdemy.getLectureId())
Expand All @@ -46,15 +47,28 @@ public static LectureResponseDTO.KeywordRecommendLectureInfo toKeywordRecommendL
.avgRating(lectureUdemy.getAvgRating())
.thumbnail(lectureUdemy.getThumbnail())
.instructorName(lectureUdemy.getInstructorName())
.topword1(lectureUdemy.getTopic())
.topword2(lectureUdemy.getSubcategory())
.topword1(lectureTag.getTopword1())
.topword2(lectureTag.getTopword2())
.topword3(lectureTag.getTopword3())
.topword4(lectureTag.getTopword4())
.topword5(lectureTag.getTopword5())
.build();
}

public static LectureResponseDTO.KeywordRecommendLectureDto toKeywordRecommendLectureDto(List<LectureUdemy> lectureUdemyList) {
public static LectureResponseDTO.KeywordRecommendLectureDto toKeywordRecommendLectureDto(
List<LectureUdemy> lectureUdemyList, List<LectureTag> lectureTagList) {

Map<Integer, LectureTag> lectureTagMap = lectureTagList.stream()
.collect(Collectors.toMap(LectureTag::getLectureUdemyId, tag -> tag));

List<LectureResponseDTO.KeywordRecommendLectureInfo> lectureInfos = lectureUdemyList.stream()
.map(LectureConverter::toKeywordRecommendLectureInfo)
.map(lectureUdemy -> {
LectureTag lectureTag = lectureTagMap.get(lectureUdemy.getLectureId());
if (lectureTag == null) {
throw new IllegalArgumentException("Matching LectureTag not found for lectureId: " + lectureUdemy.getLectureId());
}
return toKeywordRecommendLectureInfo(lectureUdemy, lectureTag);
})
.collect(Collectors.toList());

return LectureResponseDTO.KeywordRecommendLectureDto.builder()
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/khu/bigdata/infou/implement/LectureService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,26 @@ public LectureResponseDTO.KeywordRecommendLectureDto findRecommendedLectureByKey
throw new IllegalArgumentException("Keyword must not be null or empty");
}

// ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ•์˜ ๋ชฉ๋ก์„ ์กฐํšŒ(topic ๋ฐ์ดํ„ฐ์— ์žˆ๋Š”์ง€ ํ™•์ธ)
List<LectureUdemy> lectureUdemyList = lectureUdemyRepository.findAllByTopic(keyword);
// ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” LectureTag ๋ชฉ๋ก ์กฐํšŒ
List<LectureTag> lectureTags = lectureTagRepository.findByTopword1ContainingOrTopword2ContainingOrTopword3ContainingOrTopword4ContainingOrTopword5Containing(
keyword, keyword, keyword, keyword, keyword);

// LectureTag ๋ชฉ๋ก์—์„œ lectureId ์ถ”์ถœ
List<Integer> lectureIds = lectureTags.stream()
.map(LectureTag::getLectureUdemyId)
.collect(Collectors.toList());

// lectureId ๋ชฉ๋ก์„ ์‚ฌ์šฉํ•˜์—ฌ LectureUdemy ๋ชฉ๋ก ์กฐํšŒ
List<LectureUdemy> lectureUdemyList = lectureUdemyRepository.findByLectureIdIn(lectureIds);

// ์กฐํšŒ๋œ ๊ฐ•์˜ ๋ชฉ๋ก์„ AvgRating๊ณผ NumReviews์˜ ๊ฐ’์„ ๊ณฑํ•œ ๊ฐ’์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
List<LectureUdemy> sortedList = lectureUdemyList.stream()
.sorted(Comparator.comparingDouble((LectureUdemy lecture) -> lecture.getAvgRating() * lecture.getNumReviews()).reversed())
.limit(1000) // 1000๊ฐœ๋กœ ์ œํ•œ
.collect(Collectors.toList());

// ์กฐํšŒ๋œ ๊ฐ•์˜ ๋ชฉ๋ก์„ DTO๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜
return LectureConverter.toKeywordRecommendLectureDto(sortedList);
// ์กฐํšŒ๋œ ๊ฐ•์˜ ๋ชฉ๋ก๊ณผ ๋Œ€์‘๋˜๋Š” LectureTag๋ฅผ ๋งคํ•‘ํ•˜์—ฌ DTO๋กœ ๋ณ€ํ™˜
return LectureConverter.toKeywordRecommendLectureDto(sortedList, lectureTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import khu.bigdata.infou.domain.LectureTag;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface LectureTagRepository extends JpaRepository<LectureTag, Long> {

Optional<LectureTag> findByLectureUdemyId(Integer lectureId);

List<LectureTag> findByTopword1ContainingOrTopword2ContainingOrTopword3ContainingOrTopword4ContainingOrTopword5Containing(
String keyword1, String keyword2, String keyword3, String keyword4, String keyword5);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface LectureUdemyRepository extends JpaRepository<LectureUdemy, Long

List<LectureUdemy> findAllBySubcategory(String subcategory);

List<LectureUdemy> findAllByTopic(String topic);
List<LectureUdemy> findByLectureIdIn(List<Integer> lectureIdList);

Optional<LectureUdemy> findByLectureId(Integer lectureId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static class KeywordRecommendLectureInfo {
private float price;
private String instructorName;

// todo: topword1 ~ 5๊นŒ์ง€ ์ถ”๊ฐ€ -> lecture_tag ํ…Œ์ด๋ธ”์—์„œ ๊ฐ€์ ธ์˜ค๊ธฐ
private String topword1;
private String topword2;
private String topword3;
Expand Down

0 comments on commit 9b092d3

Please sign in to comment.