-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # build.gradle # src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java # src/main/java/com/mpnp/baechelin/store/service/StoreService.java
- Loading branch information
Showing
13 changed files
with
165 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
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
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
54 changes: 47 additions & 7 deletions
54
src/main/java/com/mpnp/baechelin/common/QueryDslSearch.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,31 +1,71 @@ | ||
package com.mpnp.baechelin.common; | ||
|
||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.core.types.dsl.StringPath; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
import static com.mpnp.baechelin.common.QuerydslLocation.getBooleanBuilder; | ||
import static com.mpnp.baechelin.store.domain.QStore.store; | ||
|
||
public class QueryDslSearch { | ||
public static BooleanExpression matchAddress(String sido, String sigungu) { | ||
// sido가 null이면 sigungu는 무조건 null | ||
// sido가 null이 아니면 sigungu는 null 또는 not null | ||
|
||
public static BooleanExpression matchAddressWithSido(String sido) { | ||
if (StringUtils.isEmpty(sido)) { | ||
return null; | ||
} else if (StringUtils.isEmpty(sigungu)) { | ||
return null; | ||
} | ||
|
||
return Expressions.numberTemplate( | ||
Integer.class, | ||
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0); | ||
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0); | ||
} | ||
private static BooleanExpression matchAddressWithSidoAndSigungu(String sido, String sigungu) { | ||
|
||
public static BooleanExpression matchKeyword(String keyword) { | ||
// sido가 null이면 sigungu는 무조건 null | ||
if (StringUtils.isEmpty(sido)) { | ||
return null; | ||
} else if (StringUtils.isEmpty(sigungu)) { | ||
// sido가 null이 아니고 sigungu가 null이면 sido 검색 결과 리턴 | ||
return Expressions.numberTemplate( | ||
Integer.class, | ||
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0); | ||
} else if (sigungu.split(" ").length > 1) { | ||
// sigungu가 도/시/구 로 나눠져있을 때 (ex. 경기도 성남시 분당구) | ||
// 정확한 검색을 위해 + 연산자 추가 | ||
return Expressions.numberTemplate( | ||
Integer.class, | ||
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu.split(" ")[0] + " +" + sigungu.split(" ")[1]).gt(0); | ||
} else { | ||
return Expressions.numberTemplate( | ||
Integer.class, | ||
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0); | ||
} | ||
} | ||
|
||
private static BooleanExpression matchKeyword(String keyword) { | ||
if (StringUtils.isEmpty(keyword)) { | ||
return null; | ||
} | ||
return Expressions.numberTemplate( | ||
Integer.class, | ||
"function('match', {0}, {1}, {2})", store.name, store.category, keyword).gt(0); | ||
} | ||
|
||
public static BooleanBuilder getSearchBooleanBuilder(String sido, String sigungu, String keyword, String category, List<String> facility) { | ||
BooleanBuilder builder = new BooleanBuilder(); | ||
|
||
// 지역 fulltext search | ||
builder.and(matchAddressWithSidoAndSigungu(sido, sigungu)); | ||
|
||
// 검색어 fulltext search | ||
builder.and(matchKeyword(keyword)); | ||
|
||
// 카테고리, 시설 | ||
builder.and(getBooleanBuilder(category, facility, builder)); | ||
|
||
return builder; | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.