Skip to content

Commit

Permalink
refactor: ft 한글 필드에 대해 n-parser 적용 (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
jminkkk authored Oct 24, 2024
1 parent b3e8155 commit 4be0799
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE template DROP INDEX idx_template_fulltext;
ALTER TABLE template ADD FULLTEXT INDEX idx_template_fulltext (title, description) WITH PARSER ngram;
4 changes: 2 additions & 2 deletions backend/src/test/java/codezap/fixture/TemplateFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public class TemplateFixture {
public static Template get(Member member, Category category) {
return new Template(member, "Template 1", "Description 1", category);
return new Template(member, "안녕", "Description 1", category);
}

public static Template getPrivate(Member member, Category category) {
return new Template(member, "Template 1", "Description 1", category, Visibility.PRIVATE);
return new Template(member, "안녕하세요", "Description 1", category, Visibility.PRIVATE);
}
}
2 changes: 1 addition & 1 deletion backend/src/test/java/codezap/global/DatabaseCleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void truncate(List<String> queries, JdbcTemplate jdbcTemplate) {

private void createIfNotExistFullTextIndex(JdbcTemplate jdbcTemplate) {
if (!indexExists(jdbcTemplate, "template", "idx_template_fulltext")) {
jdbcTemplate.execute("ALTER TABLE template ADD FULLTEXT INDEX idx_template_fulltext (title, description)");
jdbcTemplate.execute("ALTER TABLE template ADD FULLTEXT INDEX idx_template_fulltext (title, description) WITH PARSER ngram");
}
if (!indexExists(jdbcTemplate, "source_code", "idx_source_code_fulltext")) {
jdbcTemplate.execute("ALTER TABLE source_code ADD FULLTEXT INDEX idx_source_code_fulltext (content, filename)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void testFindWithAllCriteria() {
@DisplayName("검색 테스트: 검색 결과가 없는 경우 빈 리스트 반환 성공")
void testFindWithNoResults() {
Specification<Template> spec = new TemplateSpecification(
null, "NonexistentKeyword", null, null, null
null, "없지롱", null, null, null
);
Page<Template> result = templateRepository.findAll(spec, PageRequest.of(0, 10));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void findAllFailureWithNullPageable() {
@DisplayName("검색 기능: 키워드로 템플릿 목록 조회 성공")
void findAllSuccessByKeyword() {
Long memberId = null;
String keyword = "Template";
String keyword = "안녕";
Long categoryId = null;
List<Long> tagIds = null;
Visibility visibility = null;
Expand All @@ -139,8 +139,7 @@ void findAllSuccessByKeyword() {
Page<Template> actual = sut.findAllBy(memberId, keyword, categoryId, tagIds, visibility, pageable);

assertThat(actual.getContent()).containsExactlyInAnyOrder(templates.stream()
.filter(template -> template.getTitle().contains(keyword) || template.getDescription()
.contains(keyword))
.filter(template -> template.getTitle().contains(keyword) || template.getDescription().contains(keyword))
.toArray(Template[]::new));
}

Expand Down Expand Up @@ -300,7 +299,7 @@ void findAllSuccessByMemberIdAndVisibility() {
@DisplayName("검색 기능: 모든 검색 기준으로 템플릿 목록 조회 성공")
void findAllSuccessWithAllCriteria() {
Long memberId = member1.getId();
String keyword = "Template";
String keyword = "안녕하세요";
Long categoryId = category1.getId();
List<Long> tagIds = List.of(tag1.getId(), tag2.getId());
Visibility visibility = Visibility.PUBLIC;
Expand All @@ -318,7 +317,7 @@ void findAllSuccessWithAllCriteria() {
@DisplayName("검색 기능: 검색 결과가 없는 경우 빈 리스트 반환 성공")
void findAllSuccessWithNoResults() {
Long memberId = null;
String keyword = "NonExistentKeyword";
String keyword = "설명";
Long categoryId = null;
List<Long> tagIds = null;
Visibility visibility = null;
Expand Down

0 comments on commit 4be0799

Please sign in to comment.