Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 일반 검색 시 특수문자 무시하도록 수정 #248

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class NovelCustomRepositoryImpl implements NovelCustomRepository {

@Override
public Page<Novel> findSearchedNovels(Pageable pageable, String query) {
String searchQuery = query.replaceAll("\\s+", "");
String searchQuery = query.replaceAll("\\s+", "").replaceAll("[^a-zA-Z0-9가-힣]", "");

BooleanExpression titleContainsQuery = getSpaceRemovedString(novel.title).containsIgnoreCase(searchQuery);
BooleanExpression authorContainsQuery = getSpaceRemovedString(novel.author).containsIgnoreCase(searchQuery);
BooleanExpression titleContainsQuery = getCleanedString(novel.title).containsIgnoreCase(searchQuery);
BooleanExpression authorContainsQuery = getCleanedString(novel.author).containsIgnoreCase(searchQuery);

List<Novel> novelsByTitle = jpaQueryFactory
.selectFrom(novel)
Expand Down Expand Up @@ -67,9 +67,9 @@ public Page<Novel> findSearchedNovels(Pageable pageable, String query) {
return new PageImpl<>(result.subList(start, end), pageable, total);
}

private StringTemplate getSpaceRemovedString(StringPath stringPath) {
private StringTemplate getCleanedString(StringPath stringPath) {
return Expressions.stringTemplate(
"REPLACE(REPLACE({0}, ' ', ''), CHAR(9), '')",
"CAST(REGEXP_REPLACE(REPLACE(REPLACE({0}, ' ', ''), CHAR(9), ''), '[^a-zA-Z0-9가-힣]', '') AS STRING)",
stringPath
);
}
Expand Down
Loading