php利用scws实现mysql全文搜索功能
这篇文章主要介绍了php利用scws实现mysql全文搜索功能的方法,可通过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%,

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



MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.
