coreseek 安装及使用方法详解
coreseek 安装及使用
一般站点都需要搜索功能,如果是php+mysql站点,建议选择coreseek,如果是java站点建议使用lucene,coreseek 是一款很好的中文全文检索/搜索软件,支持高速建立索引、有很强的扩展性、支持分布式检索,支持不同的搜索模式(’完全匹配’,’短语匹配’,’任一匹配’)。
logo1
如果下面的过程遇到问题,请参考 coreseek安装遇到的错误和问题解决方案 我把安装和配置遇到的常见问题和解决办法都总结在那里了。
一、coreseek 安装
1:安装mmseg分词库
wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-3.2.14-beta.tar.gz
tar -zxvf coreseek-3.2.14-beta.tar.gz
cd coreseek-3.2.14-beta
cd mmseg-3.2.14
./bootstrap
./configure --prefix=/usr/local/mmseg3 #配置安装目录
make
make install
cd ..
2:安装coreseek
cd csft-3.2.14
sh buildconf.sh
./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql=/usr/local/mysql
make
make install
cd..
3:测试mmseg分词和coreseek检索
cd /usr/local/src/coreseek-3.2.14
cd testpack
cat var/test/test.xml #现实的是中文的内容
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml #显示xml文件内容
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all #建立索引
/usr/local/coreseek/bin/search -c etc/csft.conf # 进行搜索
二、coreseek配置和使用
1:配置example.conf文件
cd /usr/local/coreseek/etc
cp sphinx-min.conf.dist example.conf
对example.conf的配置进行改造,变成我们所需的配置文件。
source example
{
type = mysql
sql_host = localhost
sql_user = ***
sql_pass = ***
sql_db = ***
sql_port = 3306
sql_sock = /tmp/mysql.sock
sql_query_pre = SET NAMES utf8
sql_query = SELECT id,content FROM table_name #不管表的主键叫什么,查出来的结果都是为id
sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
sql_query_info = SELECT * FROM table WHERE id=$id LIMIT 100#命令行查询时,从数据库读取原始数据信息
}
#index定义
index example
{
source = example #对应的source名称
path = /usr/local/coreseek/var/data/example/ #请修改为实际使用的绝对路径
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
#中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
#charset_dictpath = etc/ #Windows环境下设置,/符号结尾,最好给出绝对路径,
charset_type = zh_cn.utf-8
}
#全局index定义
indexer
{
mem_limit = 128M
}
#searchd服务定义
searchd
{
listen = 9312
read_timeout = 5
max_children = 60
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = /usr/local/coreseek/var/log/searchd_example.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = /usr/local/coreseek/var/log/searchd_example.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = /usr/local/coreseek/var/log/query_example.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
}
2:开启searchd服务 (这点很重要)
coreseek刚安装后searchd服务是没开启的,需要先开启,不然创建索引的时候会出错。
先在 /usr/local/src/coreseek/var/log下创建一个searchd_example.pid文件,然后执行下面的代码:
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/example.conf
3:创建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/example.conf --all --rotate
出现下面的提示:
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
using config file '/usr/local/coreseek/etc/example.conf'...
indexing index 'example'...
collected 1 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1 docs, 631 bytes
total 0.005 sec, 118854 bytes/sec, 188.35 docs/sec
total 1 reads, 0.000 sec, 0.8 kb/call avg, 0.0 msec/call avg
total 5 writes, 0.000 sec, 0.5 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=14094).
说明coreseek已经可以使用了。
可以把创建索引的命令写入crontab里面进行定时,实时更新索引。
4:php 和 coreseek 结合进行查询
先下载sphinxapi,然后文件引入结合php进行查询,下面更多参数的详解和配置,可以参考 coreseek api php手册
require_once('sphinxapi');
$s = new SphinxClient();
$s->SetServer('127.0.0.1','9312'); //设置searchd的主机名和TCP端口
$s->SetConnectTimeout(1); // 设置连接超时
$s->SetMatchMode(SPH_MATCH_BOOLEAN); //设置全文查询的匹配模式
$page_size=20;//自己定义的页数
$s->SetLimits($start,$page_size); //设置返回结果集偏移量和数目
$s->SetSortMode( SPH_SORT_EXTENDED,"good_count DESC, @id DESC" ); // 设置排序
$s->SetArrayResult(true);//控制搜索结果集的返回格式
$res = $s->Query($keyword,'*');// 执行搜索查询
$res_list = $res['matches'];
安装遇到的错误和问题解决方案
1、测试mmseg分词的时候
执行
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
提示下面的错误:
/usr/local/coreseek/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
原因:sphinx indexer的依赖库ibmysqlclient.so.18找不到。
解决办法:
vi /etc/ld.so.conf
加入 /usr/local/mysql/lib
然后运行 ldconfig
问题解决
2、执行索引的时候
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf --all --rotate
提示下面的错误:
FATAL: failed to open /usr/local/coreseek/var/data/ttd_article/.tmp.spl: No such file or directory, will not index. Try --rotate option.
原因:source源找不到mysql.sock
解决办法:在配置文件csft_ttd_search.conf(自己创建的文件)的 source源 加入下面的代码
sql_sock = /tmp/mysql.sock
3、执行索引的时候,出现的警告,导致索引没创建成功
WARNING: failed to open pid_file '/usr/local/coreseek/var/log/searchd_ttd_search.pid'.
WARNING: indices NOT rotated.
原因:找不到searchd_ttd_search.pid文件
解决办法:在’/usr/local/coreseek/var/log 下创建searchd_ttd_search.pid文件
再执行/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf –all –rotate
出现了另外一个警告:
WARNING: failed to scanf pid from pid_file '/usr/local/coreseek/var/log/searchd_ttd_search.pid'.
WARNING: indices NOT rotated.
原因:虽然创建了searchd_ttd_search.pid文件,但是里面没有写入进程id
解决办法(根本原因):在执行索引之前没有启动searchd服务,因此执行下面的命令
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/ttd_search.conf
出现了期待已久的成功提示:
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
using config file '/usr/local/coreseek/etc/ttd_search.conf'...
listening on all interfaces, port=9312
rotating index 'mysql': success
coreseek 安装及使用方法详解的更多相关文章
- postman的安装和使用方法详解
文章来源:http://www.cnplugins.com/tool/specify-postman-methods.html 非官网安装 这是一种直接通过打包已经安装的扩展程序的方式,来进行我认为的 ...
- Ubuntu下安装JDK图文教程详解 jdk-java6-30 .bin 的处理方法
Ubuntu下安装JDK图文教程详解 jdk-java6-30 .bin 的处理方法: https://blog.csdn.net/mingjie1212/article/details/485250 ...
- SQL Server2012 安装方法详解
SQL Server2012 安装方法详解 - MonkeyBrothers的博客 - CSDN博客 https://blog.csdn.net/monkeybrothers/article/deta ...
- C++调用JAVA方法详解
C++调用JAVA方法详解 博客分类: 本文主要参考http://tech.ccidnet.com/art/1081/20050413/237901_1.html 上的文章. C++ ...
- CURL使用方法详解
php采集神器CURL使用方法详解 作者:佚名 更新时间:2016-10-21 对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程 ...
- PHP cURL应用实现模拟登录与采集使用方法详解
对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程链接的数据,但是它的可控制性太差了,对于各种复杂情况的采集情景,file_get_co ...
- Python安装、配置图文详解(转载)
Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境(I ...
- Windows-008-VirtualBox 安装 Win7 前沿配置详解
此文主要讲述在 Windows 系统下安装虚拟机 VirtualBox,及用 VirtualBox 安装 Win7 Professional 64bit 操作系统的前沿配置为例,配以图文进行详细的讲解 ...
- webpack安装配置使用教程详解
webpack安装配置使用教程详解 www.111cn.net 更新:2015-09-01 编辑:swteen 来源:转载 本文章来为各位详细的介绍一下关于webpack安装配置使用教程吧,这篇文章对 ...
随机推荐
- SQL Server 2012 新特性:新增和修改函数
转换函数 1.PARSE Parse是把字符串类型转化为想要的类型,看看和convert和cast的区别 SELECT PARSE ('2.111111' AS f ...
- I2C子系统之驱动SSD1306 OLED
理解I2C设备驱动框架,主要围绕四个结构体去分析就容易了. struct i2c_algorithm:提供I2C协议的实现的操作,如:master_xfer实现数据收发的最基本方法. struct i ...
- Linux之od命令详解
功能说明:输出文件内容.语 法:od [-abcdfhilovx][-A <字码基数>][-j <字符数目>][-N <字符数目>][-s <字符串字符数&g ...
- MYSQL 导入Excel数据到数据库中
1,先把excel的数据整理整齐,如每列都要保持同样的格式:就一列一列的数据: 2,导出excel的数据为CSV格式,即把excel的数据另存为xxxx.csv;: 3,用EditPlus工具将xxx ...
- win8改win7笔记
内存<=4G,选32位(×86) 内存>=4G,选64位(×64) (非必须) BIOS设置 USB Boot Support Disabled改为Enabled(如 ...
- 代码管理工具 --- git的学习笔记二《git的工作原理》
通过几个问题来学习代码管理工具之git 一.git是什么?为什么要用它?使用它的好处?它与svn的区别,在Mac上,比较好用的git图形界面客户端有 git 是分布式的代码管理工具,使用它是因为,它便 ...
- 数据库 数据库SQL语句一
字符和日期 --字符和日期都要包含在单引号中 --字符大小写敏感,日期格式敏感 --默认的日期格式是DD-MON-RR --查询当前系统时间 SQL> select sysdate from d ...
- [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- .NET跨平台之旅:增加文件日志功能遇到的挫折
在将我们的ASP.NET 5示例站点(about.cnblogs.com)升级至ASP.NET 5 RC1的时候,我们增加了控制台日志功能. 在ASP.NET 5添加日志功能很简单,只需在projec ...
- Ajax入门(一)
最近开始学习Ajax了0.0,虽然其他的还没巩固,但既然学了就先写下来吧... Ajax的定义呢,百度吧= =...就觉得最实用的地方就是页面无刷新,但网页实现了与后台的同步更新. 1, 首先创建 ...