Skip to content

Commit

Permalink
Merge pull request #163 from HS-Continuity/KAN-749--feat/키워드-검색-로직-강화
Browse files Browse the repository at this point in the history
KAN-749 feat: 키워드 검색 로직 강화
  • Loading branch information
Koo-Tae-Ho authored Aug 6, 2024
2 parents d1ff44e + 179db1d commit 300be08
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.yeonieum.productservice.domain.category.entity.QProductDetailCategory;
import com.yeonieum.productservice.domain.product.entity.Product;
Expand Down Expand Up @@ -44,6 +46,13 @@ public Page<Product> findByKeywords(List<String> keywords, Pageable pageable) {

query.where(predicate).distinct();

// CASE 문을 사용하여 상품 이름 검색 결과에 높은 우선순위를 부여
NumberExpression<Integer> sortOrder = new CaseBuilder()
.when(product.productName.contains(keywords.get(0))).then(1)
.otherwise(2);

query.orderBy(sortOrder.asc(), product.productName.asc());

// 쿼리 결과 가져오기 및 페이징 처리
List<Product> productList = query
.offset(pageable.getOffset())
Expand Down

0 comments on commit 300be08

Please sign in to comment.