当前位置:网站首页>MySQL - full text index
MySQL - full text index
2022-07-24 10:31:00 【Camellia Populus】
Full-text index ( English Search )
- Full text index is mainly based on word segmentation index of string type , Mainly based on CHAR、VARCHAR and TEXT Field on , In order to be able to query string type fields with large amount of data more quickly .
- Full text index is based on words ,MySQL The default participle is that all special symbols other than letters and numbers are participles .
- MySQL from 3.23.23 Full text indexing is now supported ,MySQL5.6 In the past, it was only in the storage engine for MyISAM Create a full-text index on the data table of ,5.6 after InnoDB Start supporting full-text indexing (5.7 After that, Chinese full-text indexing is supported ) . By default , The search execution of full-text index is case insensitive , If the field associated with the full-text index is a binary data type , Just do a case sensitive search .
1. Define indexes when creating tables
CREATE TABLE tablename(
propname1 type1,
propname2 type2,
……
propnamen type..n,
FULLTEXT INDEX | KEY
[indexname] (propnamen [(length)] ) );
Usage method
mysql> create table class(id int, name varchar(64), comment varchar(64), FULLTEXT INDEX comment_index(comment)); // establish class surface , Appoint comment For full-text indexing
mysql> show create table class; // Query table structure
mysql> insert into class values(1, ' Zhang San ', 'I''m Zhang san'); // insert data 1
mysql> insert into class values(2, ' Li Si ', 'I''m Li si'); // insert data 2
mysql> select * from class where match(comment) AGAINST('Li'); // Inquire about
2. Create an index on an existing table
Method 1 :
stay MySQL In addition to creating a full-text index through SQL sentence FULLTEXT INDEX To realize the external , You can also use SQL sentence CREATE FULLTEXT INDEX To achieve , Its grammatical form is as follows :
CREATE FULLTEXT INDEX indexname
ON tablename( propname1 [ ( length ) ] );
In the above statement , keyword CREATE FULLTEXT INDEX For creating a full-text index .
The following example table already exists , It can be done by CREATE Statement to create a full-text index :
mysql> create table class(id int, name varchar(64), comment varchar(64)); // establish class surface
mysql> create FULLTEXT INDEX comment_index ON class(comment); // Add full text index
mysql> show create table class; // Query table structure
mysql> insert into class values(1, ' Zhang San ', 'I''m Zhang san'); // insert data 1
mysql> insert into class values(2, ' Li Si ', 'I''m Li si'); // insert data 2
mysql> select * from class where match(comment) AGAINST('Zhang'); // Inquire about
Method 2 :
In addition to the above two ways to create a full-text index , stay MySQL You can also create a full-text index through SQL sentence ALTER To achieve , Its grammatical form is as follows :
ALTER TABLE tablename
ADD FULLTEXT INDEX|KEY indexname(propname [(length)]);
Usage method
mysql> create table class(id int, name varchar(64), comment varchar(64)); // establish class surface
mysql> alter table class add FULLTEXT INDEX comment_index(comment); // Add full text index
mysql> show create table class; // Query table structure
mysql> insert into class values(1, ' Zhang San ', 'I''m Zhang san'); // insert data 1
mysql> insert into class values(2, ' Li Si ', 'I''m Li si'); // insert data 2
mysql> select * from class where match(comment) AGAINST('Zhang'); // Inquire about // Inquire about
MySQL8 Chinese word segmentation support
The configuration file my.ini(Windows 10 The default path : C:\ProgramData\MySQL\MySQL Server 8.0) Add the following configuration items in , meanwhile restart MySQL80 service :
[mysqld] // Find this line
ngram_token_size=2 // Copy this line , Set up 2 Words are a group of search words

mysql> create table class(id int, name varchar(64), FULLTEXT INDEX name_index(name) with parser ngram); // establish class surface name Set column to full-text index , Support Chinese word segmentation index
mysql> insert into class values(1, ' Frenchman Zhang San '); // insert data 1
mysql> insert into class values(2, ' Nicholas Zhao si '); // insert data 2
mysql> select * from class where match(name) against(' Maniac '); // Only query two words

边栏推荐
- Home raiding II (leetcode-213)
- Ffmpeg splash screen solution (modify the source code and discard incomplete frames)
- 差分约束系统---1且2--2022年5月27日
- Kotlin Advanced Grammar
- Erlang学习02
- Web Security Foundation - file upload (file upload bypass)
- 分布式锁-Redission 原理分析
- In depth analysis of common cross end technology stacks of app
- Ribbon's loadbalancerclient, zoneawareloadbalancer and zoneavoidancerule are three musketeers by default
- pom文件dependency中的 scope用法
猜你喜欢

The concept and representation of a tree

MySQL - lock

Dynamic planning: robbing families and houses

Add a love power logo to your website

Curse of knowledge

2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1

Sentinel 三种流控模式

分布式锁-Redission 原理分析

《nlp入门+实战:第二章:pytorch的入门使用 》

图模型2--2022-5-13
随机推荐
图像处理:RGB565转RGB888
高精尖中心论文入选国际顶会ACL 2022,进一步拓展长安链隐私计算能力
Figure model 2-2022-5-13
Try the video for 5 minutes [easy to understand]
Deployment and analysis of coredns
Dynamic planning: robbing families and houses
ffmpeg花屏解决(修改源码,丢弃不完整帧)
关联规则--2022年7月10日
zoj-Swordfish-2022-5-6
Add a love power logo to your website
fatal: unable to commit credential store: Device or resource busy
CMS vulnerability recurrence - ultra vires vulnerability
What did zoneawareloadbalancer of ribbon and its parent class do?
JS function call download file link
【剑指 Offer II 115. 重建序列】
Erlang学习02
(3) Current situation of low code platform and R & D changes based on it basic components
Binary original code, inverse code, complement code
Implementation and traversal of binary tree and binary tree sorting tree
很佩服的一个Google大佬,离职了。。