分词搜索 sphinx3.1.1+php7+mysql
程序员文章站
2022-05-13 18:29:37
wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz tar zxf sphinx-3.1.1-612d99f-linux-amd64.tar.gz mv sphinx-3.1.1 sphinx mv s ......
- 下载sphinx3.1.1
- wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz
- 解压
- tar zxf sphinx-3.1.1-612d99f-linux-amd64.tar.gz
- 改名 sphinx 并移动到 /usr/local/
- mv sphinx-3.1.1 sphinx
- mv sphinx /usr/local/
- 到sphinx目录下创建 data,log文件夹,并赋777权限
- cd /usr/local/sphinx
- mkdir data
- chmod -r 777 data
- mkdir log
- chmod -r 777 log
- 在/usr/local/sphinx/etc 编写 sphinx.conf 配置文件
- cd /usr/local/sphinx/etc
- vim sphinx.conf
-
# # minimal sphinx configuration sample (clean, simple, functional) # source src1 { type = mysql sql_host = localhost sql_user = root sql_pass = root sql_db = test sql_port = 3306 # optional, default is 3306 sql_query_pre = set names utf8 sql_query = \ select id, group_id, unix_timestamp(date_added) as date_added, title, content \ from documents sql_attr_uint = group_id sql_attr_timestamp = date_added } index test1 { source = src1 path = /usr/local/sphinx/data min_word_len = 1 ngram_len = 1 ngram_chars = u+3000..u+2fa1f } indexer { mem_limit = 128m } searchd { listen = 9312 listen = 9306:mysql41 log = /usr/local/sphinx/log/searchd.log query_log = /usr/local/sphinx/log/query.log read_timeout = 5 max_children = 30 pid_file = /usr/local/sphinx/log/searchd.pid seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 binlog_path = /usr/local/sphinx/data }
- 进入mysql
- use test;
- source /usr/local/sphinx/etc/example.sql
- /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf test1
- /usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf
- 下载sphinxapi.php 自带的类文件缺少function
https://files.cnblogs.com/files/wxzxc/sphinxclient.zip
-
-
$sphinx = new sphinxclient(); $q = $_get['key'] ?? 'test'; //搜索关键字 $sql = ""; $host = "127.0.0.1"; $port = 9312; $index = "*"; $sphinx->setserver($host, $port); $sphinx->setconnecttimeout(10); $sphinx->setarrayresult(true); $sphinx->setmatchmode(sph_match_all); $res = $sphinx->query($q, $index); print_r($res);
运行结果如下:
-
-
结束,记得数据库数据改变后需重新生成索引
上一篇: 人参和茶在一起会产生什么火花呢
下一篇: Apple Pay本月18日凌晨入华
推荐阅读
-
HBase在淘宝主搜索的Dump中的性能调优
-
搜索引擎会抓取display:none的内容吗?_html/css_WEB-ITnose
-
C#编写了一个基于Lucene.Net的搜索引擎查询通用工具类:SearchEngineUtil
-
使用Coreseek-4.1快速搭建Sphinx中文分词 Php-Mysql 全文检索 搜
-
Element-UI下拉框select实现拼音搜索
-
Vue + Element 下拉框远程搜索回显
-
Vue+Element UI中 Select下拉框搜索
-
有道搜索和IP138的IP的API接口(PHP应用)_php实例
-
phpcms 安装 SCWS分词扩展
-
curl 抓取yahoo boss 搜索结果