Using MySQL built-in function to realize full-text search function

Source: Internet
Author: User
Tags comparison create index mysql tutorial

MATCH (Col1,col2,...) Against (expr [in BOOLEAN MODE | With QUERY expansion])

MySQL supports Full-text indexing and search capabilities.  The index of the Full-text indexed type fulltext in MySQL. Fulltext indexes can be used only for MyISAM tables; they can be created as part of a CREATE TABLE statement from a char, varchar, or text column, or subsequently added using ALTER TABLE or CREATE INDEX. For a larger dataset, enter your data into a table without a Fulltext index, and then create an index that is faster than entering the data into the existing Fulltext index.

Full-text search is performed with the match () function.

Mysql> CREATE TABLE articles (
-> ID INT UNSIGNED auto_increment not NULL PRIMARY KEY,
-> title VARCHAR (200),
-> Body TEXT,
-> Fulltext (Title,body)
->);
Query OK, 0 rows Affected (0.00 sec)
 
Mysql> INSERT into articles (Title,body) VALUES
-> (' MySQL Tutorial ', ' DBMS stands for DataBase ... '),
-> (' How to use MySQL ok ', ' after you went through a ... '),
-> (' Optimizing MySQL ', ' in this tutorial we'll show ... '),
-> (' 1001 MySQL Tricks ', ' 1. Never run mysqld as root. 2... '),
-> (' MySQL vs. Yoursql ', ' in the following database comparison ... '),
-> (' MySQL security ', ' when configured properly, MySQL ... ');
Query OK, 6 rows Affected (0.00 sec)
Records:6 duplicates:0 warnings:0
 
Mysql> SELECT * from articles
-> WHERE MATCH (title,body) against (' database ');
+----+-------------------+------------------------------------------+
| ID | Title | Body |
+----+-------------------+------------------------------------------+
| 5 | MySQL vs. Yoursql | In the following database comparison ... |
| 1 | MySQL Tutorial | DBMS stands for DataBase ... |
+----+-------------------+------------------------------------------+
2 rows in Set (0.00 sec)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.