Application of MySQL full-text search

Source: Internet
Author: User

-- Suitable for intra-site searches with over million data records and civilian-level solutions

Environment: Linux mysql4/5 (versions above 5 can be directly compiled into MySql in the form of plug-ins)

Friends who use MySQL must have the experience of searching Chinese characters. The efficiency of using like is not flattering, and it is not very satisfied with the search results. We hope to have a perfect solution. But the truth is cruel. This perfect solution may make your brains empty-handed.

The MySQL Chinese Word Segmentation full-text search that I bring to you today may give you a sense of mutual sorrow.

  The following describes how:

When there were more than seven pieces of pork, I strolled in the Cu. Suddenly I saw a big board post. (I do not remember the address ).

The general content is to modify the MySQL source code. Added the Chinese word segmentation function. The principle is based on a powerful Chinese dictionary. (For details, go to hightman.cn on the Daniel homepage)

So I have to declare it. This function is copyrighted by htman. I am not involved in copyright issues.

The good news is that the modified MySQL version of this cow was issued in GPL. Don't worry about your location (unless you want to polish it yourself ).

Well, it's a long time before you get started. I also think that I am so arrogant that the price of gold has increased again. Milk has risen from 46 to 65 boxes.

---------------------- Oh yeah so hot! ----------------------------

Start:

CD // home/apps

Wget http://www.hightman.cn/down/mysql-5.1.11-hi1.tgz

Tar zxf mysql-5.1.11-hi1.tgz

CD mysql-5.1.11-hi1

# Start compilation and add the word segmentation plug-in

./Configure -- prefix =/usr/local/MySQL -- With-charset = GBK -- With-extra-charsets = all -- With-plugins = fthightman

Make

Make install

# Make & make install is a long process (depending on machine performance)

# Copy my. CNF to the system startup Item

CP/usr/local/MySQL/share/MySQL/my-medium.cnf/etc/My. CNF

# Add a MySQL user group

Groupadd MySQL

Useradd-G MySQL

# Initialization

CD/usr/local/MySQL

Bin/mysql_install_db -- user = MySQL | Note: -- user = MySQL initializes the table and requires mysql users

# Set access permissions for MySQL and root users. First, go to the MySQL directory.

CD/usr/local/MySQL

Chown-r root/usr/local/MySQL | Note: Set root to access/usr/local/mysq

Chown-r MySQL/usr/local/MySQL/var | Note: Set mysql users to access/usr/local/MySQL/var.

Chgrp-r MySQL/usr/local/MySQL | Note: Set the MySQL group to access/usr/local/mysq.

Bin/mysqld_safe -- user = MySQL & | start

# Set MySQL to be started upon startup and go to the source code directory.

CD/usr/local/MySQL/share/MySQL

CP mysql. Server/etc/init. d/MySQL

CD/etc/rc3.d

Ln-S ../init. d/MySQL s85mysql

Ln-S ../init. d/MySQL k85mysql

CD/etc/rc5.d

Ln-S ../init. d/MySQL s85mysql

Ln-S ../init. d/MySQL k85mysql

CD ../init. d

Chmod 755 MySQL

# Rc3.d rc5.d understand what is going on. If you do not understand it, you can study it yourself.

Restart the mysqld Server

Whereis MySQL

/Etc/init. d/MySQL

Service MySQL

/Etc/init. d/MySQL START | stop | restart

# Assume that you have an Apche PHP environment.

Start:

Note. The default character encoding of MySQL is GBK. Therefore, we recommend that you change the default MySQL encoding to utf8 of GBK.

Databaseb1

Show databases;

Use db1;

# A Table named Table1 in db1

The Table1 field is:

Aid

GID

UID

Atitle

Acontent

Note. Atitle and acontent are the content we need to retrieve.

The full text index (Fulltext) is created below.

Alter Table1 add Fulltext ft_gbk (atitle, acontent) with parser hightman;

In this way, the index is built.

The PHP query statement is

Select * From Table1 where match (atitle, acontent) against ('$ keyword ');

The returned results can be referenced just like normal ones.

It is worth mentioning that the speed is very fast.

1 million of the data is usually retrieved in less than 0.5 seconds.

From: http://www.51testing.com/html/87/n-130087.html

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.