当前位置:网站首页>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

边栏推荐
- Sentinel 三种流控模式
- fatal: unable to commit credential store: Device or resource busy
- Implementation and traversal of binary tree and binary tree sorting tree
- New:Bryntum Grid 5.1.0 Crack
- 2022, our small goal
- Ribbon's loadbalancerclient, zoneawareloadbalancer and zoneavoidancerule are three musketeers by default
- pom文件dependency中的 scope用法
- Domain Driven practice summary (basic theory summary and analysis + Architecture Analysis and code design + specific application design analysis V) [easy to understand]
- The method modified by private can be accessed through reflection. What is the meaning of private?
- Uniapp uses PWA
猜你喜欢

Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire

ECCV 2022 | Tsinghua proposes the first transformer to embed spectral sparsity

Uniapp calendar component

Adobe substance 3D Designer 2021 software installation package download and installation tutorial

差分约束系统---1且2--2022年5月27日

In depth analysis of common cross end technology stacks of app

The concept and representation of a tree

Query about operating system security patch information

zoj1137+作业1--2022年5月28日

Websocket 协议解读-RFC6455
随机推荐
Erlang learning 01
Set up mail server with dynamic ip+mdaemon
[electronic device note 3] capacitance parameters and type selection
Application of for loop
Erlang学习01
Simply use golang SQLC to generate MySQL query code
Chapter V Modification implementation (impl) class
DSP CCS software simulation
(3) Current situation of low code platform and R & D changes based on it basic components
《nlp入门+实战:第二章:pytorch的入门使用 》
很佩服的一个Google大佬,离职了。。
Uniapp calendar component
Sentinel three flow control effects
Create a vertical seekbar from scratch
Mysql InnoDB下联合索引的索引数量?
The best time to buy and sell stocks (leetcode-121)
图像处理:RGB565转RGB888
The paper of gaojingjian center was selected into the ACL 2022 of the international summit to further expand the privacy computing capacity of Chang'an chain
Configuration description and componentization development steps of various documents in the scaffold
机器学习小试(10)使用Qt与Tensorflow创建CNN/FNN测试环境