2
- 我已經創建了mysql的索引和全文索引,後端存儲引擎是MyISAM。
mysql> show index from play_movie;
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| play_movie | 0 | PRIMARY | 1 | id | A | 42782 | NULL | NULL | | BTREE | |
| play_movie | 0 | name | 1 | name | A | 42782 | NULL | NULL | | BTREE | |
| play_movie | 1 | play_movie_ec9d726c | 1 | describe | A | 1944 | 333 | NULL | | BTREE | |
| play_movie | 1 | name_2 | 1 | name | NULL | 42782 | NULL | NULL | | FULLTEXT | |
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
- 匹配的結果。
mysql> select name from play_movie where match(name) against ('約會規則'); +------------------------+
| name |
+------------------------+
| 約會規則 第二季 |
| 約會規則 第一季 |
+------------------------+
2 rows in set (0.00 sec)
- 喜歡的結果。
mysql> select name from play_movie where name like '%約會規則%';
+------------------------------------+
| name |
+------------------------------------+
| 戀愛法則/約會規則第四季 |
| 約會規則 第一季 |
| 約會規則 第二季 |
| 約會規則第三季 |
| 約會規則第六季 |
+------------------------------------+
5 rows in set (0.04 sec)
- 解釋了上面的2選擇。
mysql> explain select name from play_movie where match(name) against ('約會規則');
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
| 1 | SIMPLE | play_movie | fulltext | name_2 | name_2 | 0 | | 1 | Using where |
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
mysql> explain select name from play_movie where name like '%約會規則%';
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
| 1 | SIMPLE | play_movie | index | NULL | name | 767 | NULL | 42782 | Using where; Using index |
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
- 喜歡用0.04秒,找到的結果,針對使用0.00秒的比賽找到的結果,但像找到比對匹配較好的效果。
- 對比賽的結果,結果看起來像約會規則第一季,錯過的結果看起來像約會規則第六季,而關鍵字是約會規則。好像全文索引沒有分割成約會規則第六季變成約會規則和第六季。
如何配置mysql或全文索引來解決這個問題?上面的單詞是中文,默認字符集是utf8。
SELECT名字從play_movie WHERE MATCH(名)反對( '約會規則*' IN BOOLEAN MODE);有用!!!但如果我搜索'約會'',我仍然沒有收到任何東西。我已經將ft_min_word_len更改爲1,然後修復索引。謝謝!!! – pengdu
@pengdu:很高興能幫助您,如果能幫助您解決問題,請不要忘記將答案標記爲「已接受」! :) – Kaivosukeltaja