본문으로 건너뛰기
목록으로

MySQL 5.7 FullText 인덱스(with ngram)

1분 읽기
mysqlfulltextindexRDBMS

기록의 목적으로 남겨둔다.

인덱스 생성

ALTER TABLE test
    ADD FULLTEXT INDEX title_f_t_index (title) WITH PARSER ngram;

검색 쿼리

SELECT t.title
FROM test t
WHERE MATCH(title) AGAINST('과자')
order by title
LIMIT 100;

특정 단어 검색이 안 될 경우

검색하는 단어가 stopword라서 발생하는 문제이다. 아래와 같이 환경변수 값을 변경해야 한다.

SET GLOBAL innodb_ft_enable_stopword = 0;

RDS라면 파라미터 그룹에서 innodb_ft_enable_stopword 값을 0으로 바꿔주면 된다.

그리고 인덱스 키를 drop 후 다시 생성해야 적용된다.

# 1
drop index title_f_t_index on test;
 
# 2
ALTER TABLE test
    ADD FULLTEXT INDEX title_f_t_index (title) WITH PARSER ngram;

참고