sphinx的安装
1.下载sphinx
没想到sphinx3解压后即可;
wget http://sphinxsearch.com/files/sphinx-3.0.2-2592786-linux-amd64.tar.gz
grep -v "^#" sphinx.conf.dist | grep -v "^\s#" | grep -v "^$" >sphinx.conf
安装依赖包:yum -y install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
不安装有可能报错误呢?
sql_query_pre = SET SESSION query_cache_type = OFF # 还特定于MySQL源代码,在预查询中禁用查询缓存(仅用于索引器连接)非常有用,因为索引查询不会经常重新运行,而且缓存结果也没有意义。这可以通过以下方式实现:
sql_ranged_throttle
远程查询限制期,以毫秒为单位。可选,默认值为0(不节流)。适用于SQL数据源(mysql
,pgsql
,mssql
)只。
索引器在数据库服务器上施加太多负载时,节流可能很有用。它会使索引器在每个范围查询步骤中以指定的毫秒数休眠一次。这种睡眠是无条件的,并且在提取查询之前执行。
在每个查询步骤之前,sql_ranged_throttle = 1000#睡眠1秒
## N-Gram索引的分词技术
## N-Gram是指不按照词典,而是按照字长来分词,这个主要是针对非英文体系的一些语言来做的(中文、韩文、日文)
## 对coreseek来说,这两个配置项可以忽略。
# ngram_len =
# ngram_chars = U+..U+2FA1F
source documents
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = # optional, default is
sql_query = \
SELECT id, group_id, title, content \
FROM documents sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO sph_counter SELECT ,MAX(id) FROM documents
sql_ranged_throttle =
}
source src1throttled : documents
{
sql_ranged_throttle =
}
index documents
{
source = documents
path = /var/data/documents
docinfo = extern
dict = keywords
mlock =
morphology = none
min_word_len = ngram_len =
ngram_chars = U+..U+2FA1F
html_strip =
}
indexer
{
mem_limit = 128M
}
searchd
{
listen =
listen = :mysql41
log = /var/log/searchd.log
query_log = /var/log/query.log
read_timeout =
client_timeout =
max_children =
persistent_connections_limit =
pid_file = /var/log/searchd.pid
seamless_rotate =
preopen_indexes =
unlink_old =
mva_updates_pool = 1M
max_packet_size = 8M
max_filters =
max_filter_values =
max_batch_queries =
workers = threads # for RT to work
binlog_path = /var/data
}
2.报错信息
执行:./searchd -c /usr/local/sphinx/etc/sphinx.conf
FATAL: failed to open '/usr/local/var/data/binlog.lock': 2 'No such file or directory
解决:配置 即可:找的位置不对: binlog_path = /var/data
2.2
执行:./indexer -c /usr/local/sphinx/etc/sphinx.conf --all
ERROR: index 'documents': sql_query_pre[1]: Query cache is disabled; restart the server with query_cache_type=1 to enable it (DSN=mysql://root:***@localhost:3306/test)
解决:mysql没有开启缓存
如果何配置查询缓存: query_cache_type 这个系统变量控制着查询缓存工能的开启的关闭。 query_cache_type=0时表示关闭,1时表示打开,2表示只要select 中明确指定SQL_CACHE才缓存。 这个参数的设置有点奇怪,、如果事先查询缓存是关闭的然而用 set @@global.query_cache_type=; 会报错 ERROR (HY000): Query cache is disabled; restart the server with query_cache_type= to enable it 、如果事先是打开着的尝试去闭关它,那么这个关闭也是不完全的,这种情况下查询还是会去尝试查找缓存。 最好的关闭查询缓存的办法就是把my.cnf 中的query_cache_type=0然后再重启mysql。
二.安装php扩展 --sphinx
我的环境是php7.官网上没有,但是在[ Browse Source ] 找到了
wget http://git.php.net/?p=pecl/search_engine/sphinx.git;a=snapshot;h=339e123acb0ce7beb2d9d4f9094d6f8bcf15fb54;sf=tgz
tar -xzf sphinx-339e123.tar.gz -C ./php-sphinx --strip-components 1 #解压后重新命名
#竟然还下不来,只能ftp上传了
解压:
tar zxf sphinx-339e123.tar.gz 编译: ./configure --with-php-config=/usr/bin/php-config --with-sphinx=/usr/local/sphinx/libsphinxclient
# 这个地方好大的坑,一直提示:Cannot find libsphinxclient headers
make && make install
PHP : /usr/bin/php
PHP_SAPI : cli
PHP_VERSION : 7.0.
ZEND_VERSION: 3.0.
PHP_OS : Linux - Linux vic 2.6.-642.13..el6.x86_64 # SMP Wed Jan :: UTC x86_64
INI actual : /usr/local/src/sphinx-339e123/tmp-php.ini
More .INIs :
CWD : /usr/local/src/sphinx-339e123
Extra dirs :
VALGRIND : Not used
=====================================================================
TIME START -- ::
=====================================================================
No tests were run.
搞了很久终于可以了;
最后一步:修改php.ini
extension = sphinx.so 然后重启php-fpm即可,执行php -m,看到有sphinx扩展说明安装成功
php -m 终于安装成功了;
2.sphinx 用php的使用
$sphinx = new SphinxClient;
$sphinx->setServer("localhost", 9312);
$sphinx->setMatchMode(SPH_MATCH_ANY); //匹配模式 ANY为关键词自动拆词,ALL为不拆词匹配(完全匹配)
$sphinx->SetArrayResult ( true ); //返回的结果集为数组
$result = $sphinx->query("test","*"); //星号为所有索引源
$count=$result['total']; //查到的结果条数
$time=$result['time']; //耗时
$arr=$result['matches']; //结果集
$id='';
for($i=0;$i<$count;$i++){
$id.=$arr[$i]['id'].',';
}
$id=substr($id,0,-1); //结果集的id字符串
三、中文分词
1.安装scws
下载:wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
./configure --prefix=/usr/local/scws
make
make install
2.下载词库
进入:cd /usr/local/scws/etc下,
wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2 #gbk
wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2 #utf8
wget http://www.xunsearch.com/scws/down/scws-dict-cht-utf8.tar.bz2 #繁体中文
[root@iZije4ffdt70xyZ etc]# ll
total
-rw-r--r-- root root Jun : rules_cht.utf8.ini
-rw-r--r-- root root Jun : rules.ini
-rw-r--r-- root root Jun : rules.utf8.ini
-rw-r--r-- root root Feb scws-dict-chs-gbk.tar.bz2
-rw-r--r-- root root Feb scws-dict-chs-utf8.tar.bz2
-rw-r--r-- root root Feb scws-dict-cht-utf8.tar.bz2
[root@iZije4ffdt70xyZ etc]# tar -jxvf scws-dict-chs-gbk.tar.bz2
dict.xdb
[root@iZije4ffdt70xyZ etc]# tar -jxvf scws-dict-chs-utf8.tar.bz2
dict.utf8.xdb
[root@iZije4ffdt70xyZ etc]# tar -jxvf scws-dict-cht-utf8.tar.bz2
dict_cht.utf8.xdb
[root@iZije4ffdt70xyZ etc]#
3.安装php扩展
cd SCWS_1.x.x/phpext
phpize
./configure --with-php-config=PHP_HOME/bin/php-config
make
make install
4.cd SCWS_1.x.x/phpext
php scws_test.php
检测结果是否正确
sphinx的安装的更多相关文章
- Sphinx(coreseek) 安装使用以及词库的扩展
1.Sphinx(coreseek) 是啥 一般而言,Sphinx是一个独立的全文搜索引擎:而Coreseek是一个支持中文的全文搜索引擎,意图为其他应用提供高速.低空间占用.高结果相关度的中文全文搜 ...
- Sphinx学习之sphinx的安装篇
一. Sphinx简介 Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检索引擎.意图为其他应用提供高速.低空间占用.高结果 相关度的全文搜索功能.Sphinx可以非常容易的与 ...
- sphinx编译安装
install sphinx wget http://sphinxsearch.com/files/sphinx-2.0.8-release.tar.gz tar zxvf sphinx--relea ...
- 搭建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例(转)
一个文档包含了安装.增量备份.扩展.api调用示例,省去了查找大量文章的时间. 搭建coreseek(sphinx+mmseg3)安装 [第一步] 先安装mmseg3 cd /var/install ...
- sphinx全文检索 安装配置和使用
公司项目刚刚导入大量产品数据,然后发现网站的产品搜索很卡,原本是原生sql的like来做模糊搜索,数据量20W的时候还可以接受,但是上百万就很卡了,所以需要做优化. 经过考虑,打算采用全文检索 sph ...
- sphinx,coreseek安装
sphinx是国外的一款搜索软件. coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文. Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本 ...
- Sphinx扩展安装安装
Coreseek官方教程中建议php使用直接include一个php文件进行操作,事实上php有独立的sphinx模块可以直接操作coreseek(coreseek就是sphinx!)已经进入了php ...
- Linux下coreseek环境安装 、mysql数据源、sphinx扩展安装及php调用
一.安装m4-1.4.13.autoconf-2.64.automake-1.11.libtool-2.2.6 下载安装m4-1.4.13.autoconf-2.64.automake-1.11.li ...
- Sphinx(Coreseek)安装和使用指南
1.安装 1.1安装mmseg ./bootstrap # 必须执行,不然安装会失败 ./configure --prefix=/usr/local/mmseg- #指定安装目录 make make ...
随机推荐
- 芝麻HTTP:redis-py的安装
对于Redis来说,我们要使用redis-py库来与其交互,这里就来介绍一下它的安装方法. 1. 相关链接 GitHub:https://github.com/andymccurdy/redis-py ...
- javascript右键菜单分析
右键菜单 思路 1.遮蔽原来的默认右键菜单 2.新建右键菜单跟随鼠标移动 3.注意边界处的位置变化 4.自定义右键内容的具体效果 具体 这样的事件涉及到有关contextmenu事件,阻止默认事件,获 ...
- 公网访问阿里云数据库MongoDB——填坑日记
业务情景 两台服务器,一台阿里云ECS云服务器(专用网络),另一台是阿里云数据库MongoDB,处于安全考虑MongoDB是不运行外网连接的,那接下来就看怎么实现公网访问. 看到上面红色的网络类型描述 ...
- 一个TokenUtils程序,亲测可用
1. Token用途 token是HTTP请求的令牌,通俗一点说是凭证,目的是防止api被随意访问获取信息. 可使用随机数生成,也可以使用用户id.密码或时间之类进行排序或者加密进行声称. token ...
- HiHocoder1415 : 后缀数组三·重复旋律3 & Poj2774:Long Long Message
题面 HiHocoder1415 Poj2774 Sol 都是求最长公共子串,\(hihocoder\)上讲的很清楚 把两个串拼在一起,中间用一个特殊字符隔开 那么答案就是排序后相邻两个不同串的后缀的 ...
- [HEOI2016]游戏
二分图匹配(网络流实现) # include <bits/stdc++.h> # define IL inline # define RG register # define Fill(a ...
- less-more使用方法及区别
Less按屏(空格,page up/page down)或按行(回车)查看文件 Less按屏(空格)或按行(回车)查看文件(不能向上翻)
- angular路由详解五(辅助路由)
在HTML文件中 //主路由 <router-outlet></router-outlet> //辅助路由 <router-outlet name="aux& ...
- 利用EF Core的Join进行多表查询
背景 话说有这么一家子,老公养了一条狗,老婆养了一只猫. 数据库的设计 人表 宠物表 通过表可以知道,宠物通过Owner指向主人的Id. 问题来了,我要和故事开头一样,老公-狗,老婆-猫,对应起来,怎 ...
- 11.python线程
基本概念 1.进程 定义: 进程就是一个程序在一个数据集上的一次动态执行过程. 组成: 进程一般由程序.数据集.进程控制块三部分组成. 程序: 我们编写的程序用来描述进程要完成哪些功能 ...