Skip to content

Commit

Permalink
Merge pull request #57 from Kusitms-29th-Kobaco-A/fix/keword-search
Browse files Browse the repository at this point in the history
fix : 키워드 검색 시 모든 키워드가 해당되야지만 검색되도록 수정
  • Loading branch information
tlarbals824 authored Mar 6, 2024
2 parents dd6a3ea + 70fdb0a commit 2715152
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public Page<Advertisement> findAllWithKeyword(Pageable pageable, List<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ where ase.file.id in (
Page<AdvertisementEntity> 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<AdvertisementEntity> findAllWithKeyword(Pageable pageable, List<String> keywordList);
Page<AdvertisementEntity> findAllWithKeyword(Pageable pageable, List<String> keywordList, Long keywordSize);


@Query("""
Expand Down Expand Up @@ -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<AdvertisementEntity> findAllWithKeywordOrderByPopularity(Pageable pageable, List<String> keywordList);
Page<AdvertisementEntity> findAllWithKeywordOrderByPopularity(Pageable pageable, @Param("keywordList") List<String> keywordList, Long keywordSize);

@Query("""
select ae
Expand All @@ -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<AdvertisementEntity> findAllWithKeywordOrderByViewCount(Pageable pageable, List<String> keywordList);
Page<AdvertisementEntity> findAllWithKeywordOrderByViewCount(Pageable pageable, List<String> keywordList, Long keywordSize);


@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> findTopLankAdvertiseIdWithKeyword(Pageable pageable, List<String> keywordList);
List<Long> findTopLankAdvertiseIdWithKeyword(Pageable pageable, List<String> keywordList, Long keywordSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Optional<AdvertiseLike> findByAdvertisementIdAndUserId(Long advertiseId,
public List<Long> findTopLankAdvertiseId(Pageable pageable, List<String> keywordList) {
if(Objects.isNull(keywordList) || keywordList.isEmpty())
return advertiseLikeJpaRepository.findTopLankAdvertiseId(pageable);
return advertiseLikeJpaRepository.findTopLankAdvertiseIdWithKeyword(pageable, keywordList);
return advertiseLikeJpaRepository.findTopLankAdvertiseIdWithKeyword(pageable, keywordList, (long) keywordList.size());
}

}

0 comments on commit 2715152

Please sign in to comment.