-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: keyword 검색 쿼리 LIKE -> MATCH 쿼리로 수정 (#77)
* fix: LIKE 쿼리 MATCH 쿼리로 수정 * refactor: CustomFunctionContributor -> MatchFunctionContributor
- Loading branch information
Showing
5 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
data/src/main/kotlin/com/kw/data/common/contributor/MatchFunctionContributor.kt
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,22 @@ | ||
package com.kw.data.common.contributor | ||
|
||
import org.hibernate.boot.model.FunctionContributions | ||
import org.hibernate.boot.model.FunctionContributor | ||
import org.hibernate.type.StandardBasicTypes.DOUBLE | ||
|
||
class MatchFunctionContributor : FunctionContributor { | ||
|
||
companion object { | ||
private const val FUNCTION_NAME = "MATCH_AGAINST" | ||
private const val FUNCTION_PATTERN = "MATCH (?1) AGAINST (?2 IN BOOLEAN MODE)" | ||
} | ||
|
||
override fun contributeFunctions(functionContributions: FunctionContributions) { | ||
functionContributions.functionRegistry | ||
.registerPattern( | ||
FUNCTION_NAME, | ||
FUNCTION_PATTERN, | ||
functionContributions.typeConfiguration.basicTypeRegistry.resolve(DOUBLE) | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
data/src/main/kotlin/com/kw/data/common/util/CustomFunction.kt
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,21 @@ | ||
package com.kw.data.common.util | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression | ||
import com.querydsl.core.types.dsl.Expressions | ||
import com.querydsl.core.types.dsl.StringPath | ||
|
||
class CustomFunction { | ||
companion object { | ||
fun match(target: StringPath, keyword: String): BooleanExpression? { | ||
if (keyword.isEmpty()) { | ||
return null | ||
} | ||
return Expressions.numberTemplate( | ||
java.lang.Double::class.java, | ||
"FUNCTION('MATCH_AGAINST', {0}, {1})", | ||
target, | ||
"$keyword*" | ||
).gt(0) | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
data/src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor
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 @@ | ||
com.kw.data.common.contributor.MatchFunctionContributor |