HI WELCOME TO KANSIRIS

Defining FULLTEXT Indexes for MySQL Full-Text Searching

Leave a Comment
in this tutorial, you will learn how to define the full-text index for performing various full-text searches in MySQL.
Before performing a full-text search in a column of a table, you must index its data. MySQL will recreate the full-text index whenever the data of the column changes. In MySQL, the full-text index is a kind of index that has a name FULLTEXT.
MySQL supports indexing and re-indexing data automatically for a full-text search enabled column. MySQL version 5.6 or later allows you to define a full-text index for a column whose data type is CHARVARCHAR or TEXT in MyISAM or InnoDB table type. Notice that MySQL supported full-text index in the InnoDB tables since version 5.6.
MySQL allows you to define the FULLTEXT index by using the CREATE TABLE statement when you create the table or ALTER TABLE or CREATE INDEX statement for the existing tables.

Defining FULLTEXT index using CREATE TABLE statement

Typically, you define the FULLTEXT index for a column when you create a new table using the CREATE TABLE statement as follows:
To create the FULLTEXT index, you place a list of comma-separated columns in parentheses after the FULLTEXT keyword.
The following statement creates a new table named posts that has a FULLTEXT index that includes the post_content column.

Defining FULLTEXT index for existing tables

In case you already have existing tables and want to define full-text indexes, you can use the ALTER TABLE statement or CREATE INDEX statement.

Defining FULLTEXT index using ALTER TABLE statement

The following syntax defines a FULLTEXT index using the ALTER TABLE statement:
You put the table_name is the ADD FULLTEXT clause that defines a FULLTEXT index for one or more columns.
For example, you can define a FULLTEXT index for the productDescription and productLine columns in the products table of the sample database as follows:

Defining FULLTEXT index using CREATE INDEX statement

You can also use the CREATE INDEX statement to create a FULLTEXT index for existing tables. See the following syntax:
The following statement creates a FULLTEXT index for the addressLine1 and addressLine2 columns of the offices table.
Notice that for a table which has many rows, it is faster to load the data into the table that has no FULLTEXT index first and then create the FULLTEXT index, than loading a large amount of data into a table that has an existing FULLTEXT index.

Removing full-text search columns

To remove a FULLTEXT index, you just delete the index using the ALTER TABLE … DROP INDEX statement. For example, the following statement removes the address FULLTEXT index in the offices table:
In this tutorial, we have shown you how to define and remove FULLTEXT indexes that support full-text search in MySQL.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.