Home > Database > Mysql Tutorial > MySQL中的全文索引_MySQL

MySQL中的全文索引_MySQL

WBOY
Release: 2016-05-30 17:10:58
Original
1043 people have browsed it

现在将MySQL全文索引的配置过程记录一下。

 

Step1:创建Student表

   CREATE TABLE `student` (

  `id` INT(11) NOT NULL AUTO_INCREMENT,

  `studentname` VARCHAR(16) NOT NULL,

  `address` VARCHAR(256) DEFAULT '北京',

  `gender` TINYINT(4) NOT NULL,

  `mymoney` DECIMAL(18,2) DEFAULT NULL,

  PRIMARY KEY (`id`),

  FULLTEXT KEY `studentname` (`studentname`)

) ENGINE=MYISAM  CHARSET=utf8
Copy after login

Step2:插入测试数据

INSERT INTO `xsh`.`student`

            (

             `studentname`,

             `address`,

             `gender`,

             `mymoney`)

VALUES (

        'happy love happy',

        '北京',

        1,

        1);
Copy after login

 

 

Step3:修改my.ini文件,重启服务

 

 my.ini (Linux 下是 my.cnf ) ,在 [mysqld] 后面加入一行“ft_min_word_len=1”,然后重启Mysql

 

可以通过SHOW  VARIABLES LIKE 'ft_min_word_len'查看结果

 

Step4:忽略权重查询(表中只有一条数据)

 

mysql默认的阀值是50%,上面‘you’在每个文档都出现,因此是100%,只有低于50%的才会出现在结果集中。  但是如果不考虑权重,那么该怎么办呢?MySQL提供了布尔全文检索(BOOLEAN FULLTEXT SEARCH)

 

SELECT * FROM student

 

WHERE MATCH(studentname) AGAINST('love'  IN BOOLEAN MODE)

 

这里只做一个简单记录,因为全文索引的基础是分词,但是MySQL不支持中文。需要通过插件或者其他手段实现@!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template