sql MyISAM的全文搜索FULLText

创建

create table products (
    id int NOT NULL AUTO_INCREMENT,
    prod_id char(10) NOT NULL,
    content text NULL,
    PRIMARY KEY(id),
    FULLTEXT(content)
) ENGINE = MyISAM;

匹配使用

select content
from products
where Match(content) Against('搜索词');
select id, Match(content) Against('搜索词') AS rank
from products;
//搜索出来的是包含了'搜索词'的等级值得 ,靠前越多,没有为0

扩展搜索

select content
from products
where Match(content) Against('搜索词' WITH QUERY EXPANSION);
//搜索匹配的,搜索匹配到的数据的相关词的其他数据行等等 按等级值排序

布尔文本搜索

select content
from products
where Match(content) Against('搜索词' IN BOOLEAN MODE);
select content
from products
where Match(content) Against('搜索词 -搜索词二*' IN BOOLEAN MODE);
//-表示排除后面的 *通用匹配

clipboard.png

mysql5.6版本innodb也开始支持fulltext

你可能感兴趣的:(全文搜索,mysql)