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 安装及使用方法详解的更多相关文章

  1. postman的安装和使用方法详解

    文章来源:http://www.cnplugins.com/tool/specify-postman-methods.html 非官网安装 这是一种直接通过打包已经安装的扩展程序的方式,来进行我认为的 ...

  2. Ubuntu下安装JDK图文教程详解 jdk-java6-30 .bin 的处理方法

    Ubuntu下安装JDK图文教程详解 jdk-java6-30 .bin 的处理方法: https://blog.csdn.net/mingjie1212/article/details/485250 ...

  3. SQL Server2012 安装方法详解

    SQL Server2012 安装方法详解 - MonkeyBrothers的博客 - CSDN博客 https://blog.csdn.net/monkeybrothers/article/deta ...

  4. C++调用JAVA方法详解

    C++调用JAVA方法详解          博客分类: 本文主要参考http://tech.ccidnet.com/art/1081/20050413/237901_1.html 上的文章. C++ ...

  5. CURL使用方法详解

    php采集神器CURL使用方法详解 作者:佚名  更新时间:2016-10-21   对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程 ...

  6. PHP cURL应用实现模拟登录与采集使用方法详解

    对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程链接的数据,但是它的可控制性太差了,对于各种复杂情况的采集情景,file_get_co ...

  7. Python安装、配置图文详解(转载)

    Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境(I ...

  8. Windows-008-VirtualBox 安装 Win7 前沿配置详解

    此文主要讲述在 Windows 系统下安装虚拟机 VirtualBox,及用 VirtualBox 安装 Win7 Professional 64bit 操作系统的前沿配置为例,配以图文进行详细的讲解 ...

  9. webpack安装配置使用教程详解

    webpack安装配置使用教程详解 www.111cn.net 更新:2015-09-01 编辑:swteen 来源:转载 本文章来为各位详细的介绍一下关于webpack安装配置使用教程吧,这篇文章对 ...

随机推荐

  1. JAVA并发编程J.U.C学习总结

    前言 学习了一段时间J.U.C,打算做个小结,个人感觉总结还是非常重要,要不然总感觉知识点零零散散的. 有错误也欢迎指正,大家共同进步: 另外,转载请注明链接,写篇文章不容易啊,http://www. ...

  2. 多值(in),范围值(between..and)

    多值检测 关键词[in]   查出年龄是23,24,28 的人员信息 select * from T_Employee  where FAge  in (23,25,28) in 后面如果跟子查询, ...

  3. Microsoft Visual SourceSafe 6.0 无法关联项目

    最近遇到Microsoft Visual SourceSafe 6.0 安装好以后, 无法关联项目,导致无法进行版本控制,研究以后,发现需要运行一个程序,在安装目录下 ..\Visual Source ...

  4. centos6.5无法访问网络

    1.在network Adapter选中,右侧是否是选中为NAT 2.打开网络和共享中心-->更改适配器设置,VMnet8和VMnet1是否是自动获取了IP,自动获取ip连接上后 3.右击本地连 ...

  5. easyUI的基础布局easyui-accordion

    ---恢复内容开始--- <html> <head> <meta charset="UTF-8"> <title>树状图</t ...

  6. 编译安装zabbix3.2

    1.1 环境准备 系统环境准备:redhat 6.6 64位mysql-5.6.34php-5.6.28zabbix-3.2.1配置前先关闭iptables和SELINUX,避免安装过程中报错. # ...

  7. 初入网络系列笔记(5)FTP协议

    一.借鉴说明,本博文借鉴以下博文 1.锤子,FTP协议,http://www.cnblogs.com/loadrunner/archive/2008/01/09/1032264.html 2.suna ...

  8. [No0000AF]去除wpf窗口标题栏ICON

    /* #region 去除标题栏ICON [DllImport("user32.dll")] static extern int GetWindowLong(IntPtr hwnd ...

  9. rxjs5.X系列 —— transform系列 api 笔记

    欢迎指导与讨论:) 前言 本文是笔者翻译 RxJS 5.X 官网各类operation操作系列的的第一篇 -- transform转换.如有错漏,希望大家指出提醒O(∩_∩)O.更详细的资料尽在rxj ...

  10. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...