Home > Backend Development > PHP Tutorial > How to use scws to implement mysql full-text search function in php_PHP tutorial

How to use scws to implement mysql full-text search function in php_PHP tutorial

WBOY
Release: 2016-07-13 10:10:56
Original
1151 people have browsed it

How to use scws to implement mysql full-text search function in php,

The example in this article describes how PHP uses scws to implement the full-text search function of mysql. Share it with everyone for your reference. The specific method is as follows:

Chinese word segmentation plug-ins like scws are quite good. I simply studied it. It contains a set of rules for proper names, names of people, names of places, digital ages, etc. You can directly separate sentences into keywords one by one according to these rules, accurately The rate is between 90% and 95%. Follow the installation instructions to put the scws extension into the PHP extension directory, download the rule files and dictionary files, and reference them in the PHP configuration file. Then you can use scws for word segmentation.

1) Modify the php extension code to be compatible with php 5.4.x

2) Fixed the problem that the limit parameter of scws_get_tops in the php extension is not allowed to be less than 10

3) libscws adds scws_fork() to branch from existing scws instances and share dictionaries/rule sets, mainly for multi-threaded development.

4) Added some versions of win32 dll extension

PHP example code is as follows:

Copy code The code is as follows:
//Instantiate the core class of word segmentation plug-in
$so = scws_new();
//Set the encoding used when segmenting words
$so->set_charset('utf-8');
//Set the dictionary used for word segmentation (the dictionary of utf8 is used here)
$so->set_dict('/path/dict.utf8.xdb');
//Set the rules used for word segmentation
$so->set_rule('/path/rules.utf8.ini ');
//Remove punctuation before word segmentation
$so->set_ignore(true);
//Whether it is a compound split, such as "Chinese" returns the three words "China + people + Chinese".
$so->set_multi(true);
//Set the text to be automatically aggregated using the two-character word segmentation method
$so->set_duality(true);
//The statement to be segmented
$so->send_text("Welcome to Mars Era IT Development");
//Get the word segmentation results. If you want to extract high-frequency words, use the get_tops method
while ($tmp = $so->get_result())
{
print_r($tmp);
}
$so->close();
?>

Note: As in the above example, the character sets of the input text, dictionary, and rule files must be unified. In addition, some mysql 4.XX does not support Chinese full-text search, and keywords can be stored Corresponding location code to facilitate full-text search.

Version list

Version Type Platform Performance Others

SCWS-1.1.x C code *Unix*/*PHP* Accuracy: 95%, Recall: 91%, Speed: 1.2MB/sec

PHP extended word segmentation speed: 250KB/sec [Download] [Documentation] [Installation Instructions]

php_scws.dll(1) PHP extension library Windows/PHP 4.4.x Accuracy: 95%, Recall: 91%,

php_scws.dll(2) PHP extension library Windows/PHP 5.2.x Accuracy: 95%, Recall: 91%,

php_scws.dll(3) PHP extension library Windows/PHP 5.3.x Accuracy: 95%, Recall: 91%,

php_scws.dll(4) PHP extension library Windows/PHP 5.4.x Accuracy: 95%, Recall: 91%,

PSCWS23 PHP source code Unlimited (UTF-8 not supported) Accuracy: 93%, Recall: 89%,

PSCWS4 PHP source code No limit Accuracy: 95%, Recall: 91%,

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932474.htmlTechArticlephp uses scws to implement the mysql full-text search function. This article describes how php uses scws to implement the mysql full-text search function. method. Share it with everyone for your reference. The specific method is as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template