peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76pola petir tersembunyi gates of olympus perihokipgsoft perkuat mahjong ways 2 di akun perihokiperihoki beri pola jitu mahjong wins 3 auto maxwin5 scatter jackpot driver ojolstrategi satpam scatter mahjongstrategi menang mahjong abc1131scatter emas pabrik wonosobomodal tipis scatter jadi cuanrtp mahjong ways supir menanginsting kuat bermain mahjong waysmengungkap keunggulan mahjong waysserunya mahjong bermodal kecil untung melimpahstrategi terbaik untuk menang mahjongterus main terus gacormenang banyak dengan scatter mahjong ways1menggali kehebatan mahjong winsrahasia nurul di mahjong waysstrategi mahjong yang mengubah permainan andateknik menang mahjong ways yang efektif

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Tạo Full Text Search trong MySQL - Freetuts
VIEW
STORED PROCEDURE
INDEX
FULL TEXT SEARCH
TRIGGER
TIPS
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Tạo Full Text Search trong MySQL

Trong bài này bạn sẽ được học các tạo index Full Text Search trong MySQL, bằng cách sử dụng từ khóa FULLTEXT trong lúc tạo bảng hoặc lệnh CREATE INDEX.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Trước khi thực hiện tìm kiếm bằng kỹ thuật full text search thì bạn phải lập chỉ mục cho cột đó, lúc này MySQL sẽ cập nhật chỉ mục mỗi khi có sự thay đổi dữ liệu, tên chỉ mục này là FULLTEXT.

* Lưu ý: Như bài trước mình có nhắc, MySQL chỉ hỗ trợ FULLTEXT cho các kiểu dữ liệu CHAR, VARCHAR hoặc TEXT, kiểu lưu trữ table phải là MyISAM hoặc InnoDB (từ phiên bản 5.6 mới có).

MySQL cho phép bạn tạo FULLTEXT ngay lệnh tạo bảng CREATE TABLE, hoặc lệnh ALTER TABLE, hoặc dùng lệnh CREATE INDEX để thêm chỉ mục vào table có sẵn.

Bài viết này được đăng tại [free tuts .net]

1. Tạo Full Text Search ngay lúc tạo bảng Create Table

Trong lệnh Create Table bạn dễ dàng thêm index full text search bằng cách sử dụng từ khóa FULLTEXT. Cú pháp như sau:

CREATE TABLE table_name(
    column_list,
    ...,
    FULLTEXT (column1,column2,..)
);

Như vậy, để tạo ra nhiều index thì bạn hãy thêm nó và cahs nhau bởi dấu phẩy. Xem ví dụ dưới đây, mình đã thêm full text search cho field post_content nằm trong table posts khi vừa mới khởi tạo chúng.

CREATE TABLE posts (
  id INT NOT NULL AUTO_INCREMENT,
  title VARCHAR(255) NOT NULL,
  body TEXT,
  PRIMARY KEY (id),
  FULLTEXT (post_content )
);

2. Tạo Full Text Search trong lệnh Alter Table

Cú pháp dưới đây giúp bạn tạo được index full text search bằng cách sử dụng lệnh alter table trong MySQL.

ALTER TABLE table_name  
ADD FULLTEXT(column_name1, column_name2,…)

Nếu bạn xem kỹ thì thực ra nó cũng không khác gì việc tạo các loại index khác, chỉ có điều kỹ thuật index mỗi loại mỗi khác.

Như phần 1, bạn có thể thêm nhiều column và cách nhau bởi dấu phâỷ.

Như trong ví dụ dưới đây mình đã thêm index cho 2 field productDescription và productLine.

ALTER TABLE products  
ADD FULLTEXT(productDescription,productLine)

3. Tạo Full Text Search bằng CREATE INDEX trong MySQL

Một cách khác cũng khá đơn giản đó là sử dụng lệnh CREATE INDEX để tạo index full text search cho một table bất kì.

CREATE FULLTEXT INDEX index_name
ON table_name(idx_column_name,...)

Ví dụ: Tạo chỉ mục full text cho hai field (addressLine1, addressLine2) nằm trong table offices.

CREATE FULLTEXT INDEX address
ON offices(addressLine1,addressLine2)

Lưu ý rằng với những table đã có lượng dữ liệu lớn thì lệnh này sẽ chạy chậm hơn bình thường,bởi MySQL sẽ mất thời gian lập chỉ mục cho những record có sẵn đó. Vì vậy bạn nên thiết kế dữ liệu thuật chuẩn và tạo chỉ mục cẩn thận thì sẽ giúp MySQL hoạt động tốt hơn.

4. Xóa Index Full Text Search như thế nào?

Nếu bạn lỡ tay tạo rồi nhưng sau muốn xóa index full text search thì sử dụng lệnh ALTER TABLE DROP INDEX nhé.

ALTER TABLE table_name
DROP INDEX index_name;

Theo như cú pháp này thì bạn phải đặt tên cho Index thì mới xóa được. Việc đặt tên cũng là cách tốt nhất để giúp bạn quản lý các chỉ mục tốt hơn.

Ví dụ dưới đây mình đã xóa Index có tên là Address từ bảng offices.

ALTER TABLE offices
DROP INDEX address;

Như vậy là mình đã hướng dẫn xong các bước để tạo chỉ mục Full Text Search trong MySQL. Đây là bài kiến thức cơ bản và là tiền đề để bạn có thể học cách truy vấn Full Text bằng lệnh Select ở các bài tiếp theo.

Cùng chuyên mục:

Hàm ENCRYPT trong MySQL

Hàm ENCRYPT trong MySQL

Cách sử dụng ENCRYPT trong MySQL

Hàm MD5 trong MySQL

Hàm MD5 trong MySQL

Cách sử dụng MD5 trong MySQL

Hàm OLD_PASSWORD trong MySQL

Hàm OLD_PASSWORD trong MySQL

Cách sử dụng OLD_PASSWORD trong MySQL

Hàm PASSWORD trong MySQL

Hàm PASSWORD trong MySQL

Cách sử dụng PASSWORD trong MySQL

Hàm ASCII trong MySQL

Hàm ASCII trong MySQL

Cách sử dụng ASCII trong MySQL

Hàm CHAR_LENGTH trong MySQL

Hàm CHAR_LENGTH trong MySQL

Cách sử dụng CHAR_LENGTH trong MySQL

Hàm CHARACTER_LENGTH trong MySQL

Hàm CHARACTER_LENGTH trong MySQL

Cách sử dụng CHARACTER_LENGTH trong MySQL

Hàm CONCAT trong MySQL

Hàm CONCAT trong MySQL

Cách sử dụng CONCAT trong MySQL

Hàm CONCAT_WS trong MySQL

Hàm CONCAT_WS trong MySQL

Cách sử dụng CONCAT_WS trong MySQL

Hàm FIELD trong MySQL

Hàm FIELD trong MySQL

Cách sử dụng FIELD trong MySQL

Hàm FIND_IN_SET trong MySQL

Hàm FIND_IN_SET trong MySQL

Cách sử dụng FIND_IN_SET trong MySQL

Hàm FORMAT trong MySQL

Hàm FORMAT trong MySQL

Cách sử dụng FORMAT trong MySQL

Hàm INSERT trong MySQL

Hàm INSERT trong MySQL

Cách sử dụng INSERT trong MySQL

Hàm INSTR trong MySQL

Hàm INSTR trong MySQL

Cách sử dụng INSTR trong MySQL

Hàm LCASE trong MySQL

Hàm LCASE trong MySQL

Cách sử dụng LCASE trong MySQL

Hàm LEFT trong MySQL

Hàm LEFT trong MySQL

Cách sử dụng LEFT trong MySQL

Hàm LENGTH trong MySQL

Hàm LENGTH trong MySQL

Cách sử dụng LENGTH trong MySQL

Hàm LOCATE trong MySQL

Hàm LOCATE trong MySQL

Cách sử dụng LOCATE trong MySQL

Hàm LOWER trong MySQL

Hàm LOWER trong MySQL

Cách sử dụng LOWER trong MySQL

Hàm LPAD trong MySQL

Hàm LPAD trong MySQL

Cách sử dụng LPAD trong MySQL

Top