-
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.
- Loading branch information
Showing
7 changed files
with
108 additions
and
9 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
31 changes: 31 additions & 0 deletions
31
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.mpnp.baechelin.common; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
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 | ||
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); | ||
} | ||
|
||
public 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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mpnp/baechelin/config/mysql/MySqlDialectCustom.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,15 @@ | ||
package com.mpnp.baechelin.config.mysql; | ||
|
||
import org.hibernate.dialect.MySQL57Dialect; | ||
import org.hibernate.dialect.function.SQLFunctionTemplate; | ||
import org.hibernate.type.StandardBasicTypes; | ||
|
||
public class MySqlDialectCustom extends MySQL57Dialect { | ||
|
||
public MySqlDialectCustom() { | ||
registerFunction( | ||
"match", | ||
new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "match(?1, ?2) against (?3 in boolean mode)") | ||
); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/test/java/com/mpnp/baechelin/store/repository/StoreQueryRepositoryTest.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,33 @@ | ||
package com.mpnp.baechelin.store.repository; | ||
|
||
import com.mpnp.baechelin.store.domain.Store; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.List; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
class StoreQueryRepositoryTest { | ||
|
||
@Autowired | ||
private StoreQueryRepository storeQueryRepository; | ||
|
||
|
||
@Test | ||
public void mysqlFullTextMath() { | ||
String sido = null; | ||
String sigungu = "강남구"; | ||
String keyword = "갈비"; | ||
|
||
List<Store> stores = storeQueryRepository.searchStores(sido, sigungu, keyword); | ||
|
||
for (Store store : stores) { | ||
System.out.println(store.getAddress()); | ||
} | ||
} | ||
|
||
} |