-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27 feat(persistence): 상품 검색 기능 작성(imageUrl 추가 예정)
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/com/helpmeCookies/product/repository/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
package com.helpmeCookies.product.repository; | ||
|
||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.product.repository.dto.ProductSearch; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, Long> { | ||
|
||
@Query("SELECT p.id AS id, p.name AS name, a.name AS artist, p.price AS price " + | ||
"FROM Product p JOIN p.artistInfo a " + | ||
"WHERE p.name LIKE %:query%") // Index 미사용 | ||
Page<ProductSearch> findByName(@Param("query") String query, Pageable pageable); | ||
|
||
@Query(value = "SELECT p.id, p.name, a.name AS artist, p.price " + | ||
"FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + | ||
"WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", | ||
countQuery = "SELECT COUNT(*) " + | ||
"FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + | ||
"WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", | ||
nativeQuery = true) // Index 사용 | ||
Page<ProductSearch> findByNameWithIdx(@Param("query") String query, Pageable pageable); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.helpmeCookies.product.repository.dto; | ||
|
||
|
||
public interface ProductSearch { | ||
Long getId(); | ||
String getName(); | ||
String getArtist(); | ||
Long getPrice(); | ||
} |