diff --git a/infra/mysql/initdb.d/init.sql b/infra/mysql/initdb.d/init.sql index 0e60a142..455f5c60 100644 --- a/infra/mysql/initdb.d/init.sql +++ b/infra/mysql/initdb.d/init.sql @@ -216,7 +216,8 @@ create table room created_at datetime(6) not null, updated_at datetime(6), primary key (id), - FULLTEXT INDEX full_index_room (title, manager_nickname) WITH PARSER ngram + FULLTEXT INDEX full_index_title (title) WITH PARSER ngram, + FULLTEXT INDEX full_index_manager_nickname (manager_nickname) WITH PARSER ngram ); create table routine diff --git a/src/main/java/com/moabam/api/domain/room/Room.java b/src/main/java/com/moabam/api/domain/room/Room.java index 4868448c..d27135a8 100644 --- a/src/main/java/com/moabam/api/domain/room/Room.java +++ b/src/main/java/com/moabam/api/domain/room/Room.java @@ -55,7 +55,8 @@ public class Room extends BaseTimeEntity { @Column(name = "id") private Long id; - @Column(name = "title", length = 20) + @Column(name = "title", + columnDefinition = "VARCHAR(20) NOT NULL, FULLTEXT INDEX full_title (title) WITH PARSER ngram") private String title; @Column(name = "password", length = 8) @@ -90,7 +91,7 @@ public class Room extends BaseTimeEntity { private String roomImage; @Column(name = "manager_nickname", - columnDefinition = "VARCHAR(30), FULLTEXT INDEX full_text_room (title, manager_nickname) WITH PARSER ngram") + columnDefinition = "VARCHAR(30), FULLTEXT INDEX full_nickname (manager_nickname) WITH PARSER ngram") private String managerNickname; @Column(name = "deleted_at") diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java index 43d9fa7a..04f7893c 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java @@ -22,8 +22,7 @@ public class RoomSearchRepository { private static final double MATCH_THRESHOLD = 0.0; - private static final String MATCH_AGAINST_TEMPLATE_ONE = "function('match_against', {0}, {1})"; - private static final String MATCH_AGAINST_TEMPLATE_TWO = "function('match_against_two', {0}, {1}, {2})"; + private static final String MATCH_AGAINST_TEMPLATE = "function('match_against', {0}, {1})"; private final JPAQueryFactory jpaQueryFactory; @@ -57,9 +56,11 @@ public List searchWithKeyword(String keyword, RoomType roomType, Long room private BooleanExpression matchAgainst(String keyword) { keyword = "\"" + keyword + "\""; - return Expressions.numberTemplate(Double.class, MATCH_AGAINST_TEMPLATE_TWO, room.title, room.managerNickname, - keyword).gt(MATCH_THRESHOLD) - .or(Expressions.numberTemplate(Double.class, MATCH_AGAINST_TEMPLATE_ONE, routine.content, keyword) + return Expressions.numberTemplate(Double.class, MATCH_AGAINST_TEMPLATE, room.title, keyword) + .gt(MATCH_THRESHOLD) + .or(Expressions.numberTemplate(Double.class, MATCH_AGAINST_TEMPLATE, room.managerNickname, keyword) + .gt(MATCH_THRESHOLD)) + .or(Expressions.numberTemplate(Double.class, MATCH_AGAINST_TEMPLATE, routine.content, keyword) .gt(MATCH_THRESHOLD)); } } diff --git a/src/main/java/com/moabam/global/config/SqlFunctionContributor.java b/src/main/java/com/moabam/global/config/SqlFunctionContributor.java index 297fcc16..e0d7bb69 100644 --- a/src/main/java/com/moabam/global/config/SqlFunctionContributor.java +++ b/src/main/java/com/moabam/global/config/SqlFunctionContributor.java @@ -13,10 +13,5 @@ public void contributeFunctions(FunctionContributions functionContributions) { .registerPattern( "match_against", "MATCH (?1) AGAINST (?2 IN NATURAL LANGUAGE MODE)", functionContributions.getTypeConfiguration().getBasicTypeRegistry().resolve(DOUBLE)); - - functionContributions.getFunctionRegistry() - .registerPattern( - "match_against_two", "MATCH (?1, ?2) AGAINST (?3 IN NATURAL LANGUAGE MODE)", - functionContributions.getTypeConfiguration().getBasicTypeRegistry().resolve(DOUBLE)); } }