Home php教程 php手册 php利用scws实现mysql全文搜索功能的方法介绍

php利用scws实现mysql全文搜索功能的方法介绍

Mar 30, 2017 pm 04:04 PM
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实例代码如下:

<?php 
//实例化分词插件核心类 
$so = scws_new(); 
//设置分词时所用编码 
$so->set_charset(&#39;utf-8&#39;); 
//设置分词所用词典(此处使用utf8的词典) 
$so->set_dict(&#39;/path/dict.utf8.xdb&#39;); 
//设置分词所用规则 
$so->set_rule(&#39;/path/rules.utf8.ini &#39;); 
//分词前去掉标点符号 
$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(); 
?>
Copy after login


注:如以上例子,输入的文字,词典,规则文件这三者的字符集必须统一,另外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)!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles