mysql全文索引FULLTEXT

2021-09-25 11:20:14 字數 1005 閱讀 5637

innodb支援全文索引

之前的舊版的mysql的全文索引只能用在myisam**的char、varchar和text的字段上。 

後來新版的mysql5.6.24上innodb引擎也加入了全文索引,所以具體資訊要隨時關注官網。

全文索引對中日韓的分詞支援。

mysql預設的分詞用的是latin,他是根據空格進行分詞的。這對於像中文的語言是沒發進行分詞的,後來mysql又內建了乙個支援中日韓文的分詞器ngram。分詞大小可以通過mysql的配置檔案進行配置ngram_token_size=2,預設是兩個。

建立ngram索引(要指定ngram,否則不支援中文)

alter table `octopus`.`material` 

add fulltext index `idx_fulltext_name`(`name`) with parser ngram;

索引查詢

1.自然語言查詢(n-gram分詞查詢的並集,例如(『北歐風格』)轉換為(「『北歐 歐風 風格'」)。)

select m.id,m.name,m.modify_date,m.material_image_urls,m.material_zip_url,m.source_type

from material m where match(name) against('北歐風格' in natural language mode);

2.短語查詢(按分詞來直接匹配)

select m.id,m.name,m.modify_date,m.material_image_urls,m.material_zip_url,m.source_type

from material m where match(name) against('北歐風格' in boolean mode);

3.統配符查詢select * from material where match(name) against('北*' in boolean mode);

mysql全文索引的坑 MySQL全文索引問題

我有乙個包含以下資料的 文章 mysql select from articles id title body 1 mysql tutorial dbms stands for database 2 how to use mysql well after you went through a 3 o...

mysql全文索引

了解 solr 之後 發現全文索引也能做檢索 故了解了下 筆記如下 建立全文索引 alter table table add fulltext index fulltext table 列1 列2 查詢方式 select from table where match 列1 列2 against 查詢...

mysql全文索引

舊版的mysql的全文索引只能用在myisam 的char varchar和text的字段上。不過新版的mysql5.6.24上innodb引擎也加入了全文索引,所以具體資訊要隨時關注官網,create table article id int auto increment not null pri...