当前位置:首页 > PHP > 正文内容

php sphinx 全文检索 中文分词

高老师4年前 (2022-11-26)PHP853

(1).下载3.4.1版本

http://sphinxsearch.com/downloads/current/

(2).配置数据源和索引(超精简版本)

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source question_src
{
    type            = mysql

    sql_host = 187.99.929.99
    sql_user = legaojiufeddssdg
    sql_pass = HjwmzCwALiGSDGfdf
    sql_db = learojiufengfdfd
    sql_port = 3306 # optional, default is 3306

    sql_query = \
        SELECT id,course_id,question_name \
        FROM think_course_question

    #sql_attr_uint = id
    sql_attr_uint   = course_id
}


index question
{
    source          = question_src
    path            = D:/test/indexData/
    ngram_len = 1
    ngram_chars = U+3000..U+2FA1F
}


indexer
{
    mem_limit       = 128M
}


searchd
{
    listen          = 9312
    listen          = 9306:mysql41
    log             = D:/test/log/searchd.log
    query_log       = D:/test/log/query.log
    read_timeout    = 5
    max_children    = 30
    pid_file        = D:/test/searchd.pid
    seamless_rotate = 1
    preopen_indexes = 1
    unlink_old      = 1
    workers         = threads # for RT to work
    binlog_path     = D:/test/data/
}

(3).生成索引 

indexer.exe   -c    ../etc/sphinx-min.conf   question

(4).启动sphinx

./searchd.exe  -c   ../etc/sphinx-min.conf

(5).php启动查询

$cl = new SphinxClient ();
$cl->SetServer($config['host'], $config['port']);
$cl->SetConnectTimeout(1);
$cl->SetLimits(0, $limit, 100);
$res = $sphinxClient->Query($keyword, 'question');

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/222.html

分享给朋友:

“php sphinx 全文检索 中文分词” 的相关文章

php抽奖概率算法

php抽奖概率算法

<?php /*  *算法学习自百度.只是学习和记录  */ header("Content-type:text/html;charset=utf-8"); //1.设置奖项,id是奖项id,name是中奖名称,v是中奖概率 $arr =&n...

php异步执行,php后台运行,如何在windows下让php后台运行

php异步执行,php后台运行,如何在windows下让php后台运行

如果想在windows中执行php,并且让php脚本在后台运行,可以用下面的cmd命令start /b php  D:\wwwroot\default\demo1\run.php例如上面的命令意思后台运行run.php,如果想用php编写异步代码: ...

php多进程实现任务管理器,定时执行任务,支持守护

php多进程实现任务管理器,定时执行任务,支持守护

主要原理是通过PHP创建多个子进程,在子进程中发送进程闹钟信号,然后再监听闹钟信号中继续发送闹钟信号。同时通过父进程设置非阻塞运行。代码如下:<?php /**  * 订单任务  */ class Order {    &n...

【一】PHP多进程学习-简单创建父子进程.理解父子进程运行流程

【一】PHP多进程学习-简单创建父子进程.理解父子进程运行流程

(1).学习的目标:学会创建父子进程,并且能够区分当前进程是父还是子;了解父进程执行过程,子进程执行过程;能够用多进程执行任务(2).相关函数学习:    (2.1)pcntl_fork()执行时:       &nbs...

php finally使用

php finally使用

<?php /**  * @throws Exception  */ function curl() {     throw  new \Exception('err...

php jsonp转json,php jsonp转数组,php jsonp转对象

php jsonp转json,php jsonp转数组,php jsonp转对象

将jsonp转为PHP数组和对象。/**  * jsonp转数组|Jsonp转json  * @param string $jsonp jsonp字符串  * @param bool $as...