php利用scws实现mysql全文搜索功能的方法_PHP
本文实例讲述了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实例代码如下:
代码如下:
//实例化分词插件核心类
$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程序设计有所帮助。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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 is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
