Skip to content

Commit

Permalink
refactor: 상품 자동 완성 조회 쿼리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Go-Jaecheol committed Oct 19, 2023
1 parent 0de0e26 commit 360771a
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Page<ProductInCategoryDto> findAllByCategoryOrderByReviewCountDesc(@Param("categ
List<Product> findAllByNameContainingFirst(@Param("name") final String name, final Pageable pageable);

@Query("SELECT p FROM Product p "
+ "JOIN Product p2 ON p2.id = :lastId "
+ "JOIN Product last ON last.id = :lastId "
+ "WHERE p.name LIKE CONCAT('%', :name, '%') "
+ "AND ((p2.name LIKE CONCAT(:name, '%') AND p.id < :lastId) OR (p.name NOT LIKE CONCAT(:name, '%') AND p.id < :lastId)) "
+ "ORDER BY "
+ "(CASE WHEN p.name LIKE CONCAT(:name, '%') THEN 1 ELSE 2 END), "
+ "p.id DESC")
+ "AND (last.name LIKE CONCAT(:name, '%') "
+ "AND ((p.name LIKE CONCAT(:name, '%') AND p.id < :lastId) OR (p.name NOT LIKE CONCAT(:name, '%'))) "
+ "OR (p.name NOT LIKE CONCAT(:name, '%') AND p.id < :lastId)) "
+ "ORDER BY (CASE WHEN p.name LIKE CONCAT(:name, '%') THEN 1 ELSE 2 END), p.id DESC")
List<Product> findAllByNameContaining(@Param("name") final String name, final Long lastId, final Pageable pageable);

@Query("SELECT new com.funeat.product.dto.ProductReviewCountDto(p, COUNT(r.id)) FROM Product p "
Expand Down

0 comments on commit 360771a

Please sign in to comment.