diff --git a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/AdvertisementRepositoryImpl.java b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/AdvertisementRepositoryImpl.java index 80aa237..8b8f314 100644 --- a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/AdvertisementRepositoryImpl.java +++ b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/AdvertisementRepositoryImpl.java @@ -58,14 +58,14 @@ public Page findAllWithKeyword(Pageable pageable, List ke } } if(orderType.equals(OrderType.RECENT)){ - return advertisementJpaRepository.findAllWithKeyword(pageable, keywordList) + return advertisementJpaRepository.findAllWithKeyword(pageable, keywordList, (long) keywordList.size()) .map(advertiseMapper::toDomain); } if(orderType.equals(OrderType.POPULAR)){ - return advertisementJpaRepository.findAllWithKeywordOrderByPopularity(pageable, keywordList) + return advertisementJpaRepository.findAllWithKeywordOrderByPopularity(pageable, keywordList, (long) keywordList.size()) .map(advertiseMapper::toDomain); } - return advertisementJpaRepository.findAllWithKeywordOrderByViewCount(pageable, keywordList) + return advertisementJpaRepository.findAllWithKeywordOrderByViewCount(pageable, keywordList, (long) keywordList.size()) .map(advertiseMapper::toDomain); } diff --git a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/repository/AdvertisementJpaRepository.java b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/repository/AdvertisementJpaRepository.java index 167abc7..7504066 100644 --- a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/repository/AdvertisementJpaRepository.java +++ b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/advertisement/repository/AdvertisementJpaRepository.java @@ -26,16 +26,18 @@ where ase.file.id in ( Page findSavedAllByUserId(Pageable pageable, @Param("userId") Long userId); @Query(""" - select distinct ae + select ae from AdvertisementEntity ae join AdvertisementKeywordEntity ak on ak.advertisement=ae and ak.keyword in ( select ke from KeywordEntity ke where ke.description in :keywordList ) + group by ae.id + having count(distinct ak.keyword) = :keywordSize order by ae.uploadDate desc """) - Page findAllWithKeyword(Pageable pageable, List keywordList); + Page findAllWithKeyword(Pageable pageable, List keywordList, Long keywordSize); @Query(""" @@ -71,15 +73,17 @@ where ake.keyword in ( select ae from AdvertisementEntity ae join AdvertisementKeywordEntity ak on ak.advertisement=ae and ak.keyword in ( - select ke - from KeywordEntity ke - where ke.description in :keywordList + select ke + from KeywordEntity ke + where ke.description in :keywordList ) + join KeywordEntity ke on ke.description in :keywordList left join AdvertiseLikeEntity ale on ale.advertisement=ae - group by ae + group by ae.id + having count(distinct ak.keyword) = :keywordSize order by count(ale.advertisement) desc """) - Page findAllWithKeywordOrderByPopularity(Pageable pageable, List keywordList); + Page findAllWithKeywordOrderByPopularity(Pageable pageable, @Param("keywordList") List keywordList, Long keywordSize); @Query(""" select ae @@ -106,9 +110,11 @@ order by count(ale.advertisement) desc from KeywordEntity ke where ke.description in :keywordList ) + group by ae.id + having count(distinct ak.keyword) = :keywordSize order by ae.viewCount desc """) - Page findAllWithKeywordOrderByViewCount(Pageable pageable, List keywordList); + Page findAllWithKeywordOrderByViewCount(Pageable pageable, List keywordList, Long keywordSize); @Modifying diff --git a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeJpaRepository.java b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeJpaRepository.java index 5f0f2e8..4741adc 100644 --- a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeJpaRepository.java +++ b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeJpaRepository.java @@ -26,15 +26,14 @@ order by count(al.advertisement.id) desc, al.advertisement.id desc @Query(""" select al.advertisement.id from AdvertiseLikeEntity al - where al.advertisement.id in ( - select a.id - from AdvertisementEntity a - join AdvertisementKeywordEntity ak on a.id = ak.advertisement.id - join KeywordEntity k on ak.keyword=k - where k.description in :keywordList + join AdvertisementKeywordEntity ak on ak.advertisement=al.advertisement and ak.keyword in ( + select ke + from KeywordEntity ke + where ke.description in :keywordList ) group by al.advertisement.id + having count(distinct ak.keyword) = :keywordSize order by count(al.advertisement.id) desc, al.advertisement.id desc """) - List findTopLankAdvertiseIdWithKeyword(Pageable pageable, List keywordList); + List findTopLankAdvertiseIdWithKeyword(Pageable pageable, List keywordList, Long keywordSize); } diff --git a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeRepositoryImpl.java b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeRepositoryImpl.java index b666a68..bebab3c 100644 --- a/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeRepositoryImpl.java +++ b/kobaco/kobaco/src/main/java/core/kobaco/infra/jpa/like/AdvertiseLikeRepositoryImpl.java @@ -45,7 +45,7 @@ public Optional findByAdvertisementIdAndUserId(Long advertiseId, public List findTopLankAdvertiseId(Pageable pageable, List keywordList) { if(Objects.isNull(keywordList) || keywordList.isEmpty()) return advertiseLikeJpaRepository.findTopLankAdvertiseId(pageable); - return advertiseLikeJpaRepository.findTopLankAdvertiseIdWithKeyword(pageable, keywordList); + return advertiseLikeJpaRepository.findTopLankAdvertiseIdWithKeyword(pageable, keywordList, (long) keywordList.size()); } }