Skip to content

Commit

Permalink
refactor: rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkim97 committed Jan 16, 2024
1 parent 339eb27 commit 15e012a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion infra/mysql/initdb.d/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/moabam/api/domain/room/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,9 +56,11 @@ public List<Room> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 15e012a

Please sign in to comment.