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

php sphinx 全文检索 中文分词

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

(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 全文检索 中文分词” 的相关文章

cookie跨域,cookie p3p跨域

cookie跨域,cookie p3p跨域

最近在公司开发一个新的项目假设项目域名是a.com,需要接入b.com的单点登陆系统。(1).首先我们会在a.com的登陆页面用iframe引入b.com来显示登陆界面,实际上登陆验证操作都是在b.com上面(2).当b.com验证通过,会在前端ajax请求a.com的回调地址,这个回调地址目的就是...

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....

php mcrypt扩展被废弃的解决方案

php mcrypt扩展被废弃的解决方案

使用openssl扩展对应替换mcrypt的函数,(比较麻烦,但是openssl是未来趋势)在新版php中编译mcrypt扩展使用一个纯php代码实现的mcrypt扩展库,git地址为https://github.com/phpseclib/mcrypt_compat,每个mcrypt的方法都已经实...

php redis事务

php redis事务

概念请参考w3school文章: redis watch ,redis exec (看完基本秒懂)(1)基本事务://连接本地的 Redis 服务 $redis = new Redis(); $redis->con...

php端口复用,php socket端口复用

php端口复用,php socket端口复用

第一次听说端口复用是在mixphp最新版本中发现的,mixphp启动监听9501端口,现在作者说可以多开几个进程来执行mixphp,我心里想了下再启动不是会端口冲突嘛,但是却没有问题,于是下载mixphp的源码解读,原来是启动http服务器使用new Co\Http\Server('0.0....

php __sleep,php阻止一个类被序列化,php __sleep作用

php __sleep,php阻止一个类被序列化,php __sleep作用

今天朋友面试遇到的问题:php如何阻止一个类被序列化,首先我想到的是使用serialize函数进行序列化对象首先会检查对象是否存在__sleep方法,如果有的话先调用__sleep方法。(1).普通序列化对象代码:class member {     ...