Home > Database > Mysql Tutorial > body text

Mysql 全文本检索

WBOY
Release: 2016-06-07 15:19:33
Original
1128 people have browsed it

mysql 全文索引 注意 并非所有的引擎都支持 全文检索 mysql最常用的引擎 INnodb 和 myisam 后者支持全文检索 前者不支持 创建表的时候指定要检索列 CREATE TABLE TEST_FULLTEXT(note_id int not null auto_increment,note_text text null ,primaty key (note_

mysql 全文索引

注意 并非所有的引擎都支持 全文检索

mysql最常用的引擎 INnodb 和 myisam 后者支持全文检索 前者不支持

创建表的时候指定要检索列

<code><span><span>CREATE</span> <span>TABLE</span> TEST_FULLTEXT(note_id <span>int</span> <span>not</span> <span>null</span> auto_increment,note_text text <span>null</span>,
primaty <span>key</span>(note_id),FULLTEXT(note_text)
)engine=myisam;</span>
</code>
Copy after login

fulltext 索引某个列 fulltext(note_text) ,在某note_text列上建立全文索引

插入数据

然后用 match()指定列 Against()指定词
如 语句

<code><span><span>select</span> *
<span>from</span> TEST_FULLTEXT
<span>where</span> <span>Match</span>(note_text) Against(<span>'hello'</span>);</span>
</code>
Copy after login

查找note_txt列中含有 hello词的行 返回的结果为 两行

<code>note_text
'hello' was said by quester 
quster say 'hello' to pp and he try again
</code>
Copy after login
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!