php利用scws实现mysql全文搜索功能的方法介绍
本文实例讲述了php利用scws实现mysql全文搜索功能的方法。分享给大家供大家参考。具体方法如下:
scws这样的中文分词插件比较不错,简单的学习了一下,它包涵一些专有名称、人名、地名、数字年代等规则集合,可以直接将语句按这些规则分开成一个一个关键词,准确率在90%-95%之间,按照安装说明把scws的扩展放入php的扩展目录里,下载规则文件和词典文件,并在php配置文件中引用它们,就可以用scws进行分词了.
1) 修改 php 扩展代码以兼容支持 php 5.4.x
2) 修正 php 扩展中 scws_get_tops 的 limit 参数不允许少于 10 的问题
3) libscws 增加 scws_fork() 从既有的 scws 实例产生分支并共享词典/规则集,主要用于多线程开发.
4) 新增部分版本的 win32 的 dll 扩展
PHP实例代码如下:
<?php //实例化分词插件核心类 $so = scws_new(); //设置分词时所用编码 $so->set_charset('utf-8'); //设置分词所用词典(此处使用utf8的词典) $so->set_dict('/path/dict.utf8.xdb'); //设置分词所用规则 $so->set_rule('/path/rules.utf8.ini '); //分词前去掉标点符号 $so->set_ignore(true); //是否复式分割,如“中国人”返回“中国+人+中国人”三个词。 $so->set_multi(true); //设定将文字自动以二字分词法聚合 $so->set_duality(true); //要进行分词的语句 $so->send_text(“欢迎来到火星时代IT开发”); //获取分词结果,如果提取高频词用get_tops方法 while ($tmp = $so->get_result()) { print_r($tmp); } $so->close(); ?>
注:如以上例子,输入的文字,词典,规则文件这三者的字符集必须统一,另外mysql 4.XX有的是不支持中文全文搜索的,可以存入关键字对应的区位码以方便全文搜索.
版本列表
版本 类型 平台 性能 其它
SCWS-1.1.x C 代码 *Unix*/*PHP* 准确: 95%, 召回: 91%, 速度: 1.2MB/sec
PHP扩展分词速度: 250KB/sec [下载] [文档] [安装说明]
php_scws.dll(1) PHP扩展库 Windows/PHP 4.4.x 准确: 95%, 召回: 91%,
php_scws.dll(2) PHP扩展库 Windows/PHP 5.2.x 准确: 95%, 召回: 91%,
php_scws.dll(3) PHP扩展库 Windows/PHP 5.3.x 准确: 95%, 召回: 91%,
php_scws.dll(4) PHP扩展库 Windows/PHP 5.4.x 准确: 95%, 召回: 91%,
PSCWS23 PHP源代码 不限 (不支持UTF-8) 准确: 93%, 召回: 89%,
PSCWS4 PHP源代码 不限 准确: 95%, 召回: 91%,
以上就是php利用scws实现mysql全文搜索功能的方法,的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
