Powerful component based mailing library for PHP – Swift Mailer
Mysql FullText 를 이용한 한글 검색시 유의 사항
주의 사항
최소 문자열 제한이 있으므로 4자 이하의 검색어는 작동되지 않는다.
예를 들어 “검색"이라는 단어를 검색하면 아무리 조건이 맞는 데이터가 있더라도 검색에 실패하게 된다. 이런 경우에는 my.ini 화일을 열고 [mysqld]아래 부분에 있는 ft_min_word_len=2 이라고 적은후 mysql을 다시 시작한다. 그리고 이전 인덱스가 있는 경우 REPAIR
Mysql FullText 를 이용한 한글 검색시 유의 사항
주의 사항
최소 문자열 제한이 있으므로 4자 이하의 검색어는 작동되지 않는다.
예를 들어 “검색"이라는 단어를 검색하면 아무리 조건이 맞는 데이터가 있더라도 검색에 실패하게 된다. 이런 경우에는 my.ini 화일을 열고 [mysqld]아래 부분에 있는 ft_min_word_len=2 이라고 적은후 mysql을 다시 시작한다. 그리고 이전 인덱스가 있는 경우 REPAIR
HOWTO Use UTF-8 Throughout Your Web Stack
Good is the enemy of Great Latin-1 is the enemy of UTF-8 You write web apps. You understand the web is global, and want to support internationalization. You want UTF-8. UTF-8 is extremely sane. Well,…
Using the Mysql FullText Index Search
Today let’s talk about a resource very useful on MySQL, the FullText Index and Search
This resource is very powerful, today on versions 5.5 is just available to MyISAM engine, but, like we can see on MySQL FullText documentation, it will be available also to InnoDB on MySQL 5.6
Usually when we want to search for a word or expression, we use LIKE ‘%word%’, in case we are looking for more than one word we use LIKE ‘%word1%word2%’, what many people don’t know is for this kind of search is expensive and not optimized to our MySQL, in this cases we solve our problems with FullText Index
the syntax is easy, MATHC() … AGAINST (), where MATCH we specified the name(s) of column(s) which we are looking for, yes, we can look for more then one column, we just need all this columns specified on our index and AGAINST is where we specify the word(s) which we are looking for, we can also, specified a search mode, but I will talk about it later
Let’s create our table and start it
CREATE TABLE `articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(200) DEFAULT NULL, `body` text, PRIMARY KEY (`id`), FULLTEXT KEY `title` (`title`,`body`) ) ENGINE=MyISAM;
INSERT INTO `articles` VALUES (1,'MySQL Tutorial','DBMS stands for DataBase ...'),(2,'How To Use MySQL Well','After you went through a ...'),(3,'Optimizing MySQL','In this tutorial we will show ...'),(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),(5,'MySQL vs. YourSQL','In the following database comparison ...'),(6,'MySQL Security','When configured properly, MySQL ...');
Let’s do our first query, looking for articles which approach ‘database’
mysql> select * from articles WHERE MATCH(title,body) AGAINST ('database'); +----+-------------------+------------------------------------------+ | id | title | body | +----+-------------------+------------------------------------------+ | 5 | MySQL vs. YourSQL | In the following database comparison ... | | 1 | MySQL Tutorial | DBMS stands for DataBase ... | +----+-------------------+------------------------------------------+ 2 rows in set (0.01 sec)
Now, let’s look for ‘database tutorial’
mysql> select * from articles WHERE MATCH(title,body) AGAINST ('database tutorial'); +----+-------------------+------------------------------------------+ | id | title | body | +----+-------------------+------------------------------------------+ | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 3 | Optimizing MySQL | In this tutorial we will show ... | | 5 | MySQL vs. YourSQL | In the following database comparison ... | +----+-------------------+------------------------------------------+ 3 rows in set (0.01 sec)
Now, let’s search for articles which approach ‘MySQL’, just a detail, all of our articles contain the word ‘MySQL’
mysql> select * from articles WHERE MATCH(title,body) AGAINST ('MySQL'); Empty set (0.00 sec)
Why? Let’s talk about Search Modes, by default, MySQL uses Natural Language mode, which tell us if the searched word match if 50% or more rows, the entire query doesn’t match.
Other good function with MySQL allow us to use, is change our search mode, let’s use Boolean mode:
mysql> select * from articles WHERE MATCH(title,body) AGAINST ('MySQL' IN BOOLEAN MODE); +----+-----------------------+------------------------------------------+ | id | title | body | +----+-----------------------+------------------------------------------+ | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 2 | How To Use MySQL Well | After you went through a ... | | 3 | Optimizing MySQL | In this tutorial we will show ... | | 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | | 5 | MySQL vs. YourSQL | In the following database comparison ... | | 6 | MySQL Security | When configured properly, MySQL ... | +----+-----------------------+------------------------------------------+ 6 rows in set (0.00 sec)
Ok, but what is the difference between they? why use boolean mode? like says on name, is true or false, let’s do a query looking for ‘database’ but I don’t want to show rows which contain the word ‘tutorial’, is this difficult? no, let’s see:
mysql> select * from articles WHERE MATCH(title,body) AGAINST ('+database -tutorial' IN BOOLEAN MODE); +----+-------------------+------------------------------------------+ | id | title | body | +----+-------------------+------------------------------------------+ | 5 | MySQL vs. YourSQL | In the following database comparison ... | +----+-------------------+------------------------------------------+ 1 row in set (0.01 sec)
Is this for today, on next article, we will learn more about the boolean mode, changing the order of relevance
YouTube에서 Unit Testing using CodeIgniter 보기
Unit Testing using CodeIgniter: