全文搜索引擎介绍(sphinx)
1.Lucence
2.sphinx
3.Apache Solr
一、简介:
Coreseek是基于sphinx更完善支持中文搜索功能。故其原理同sphinx,如下:
1、sphinx的两个主要进程indexer和searchd。
indexer任务是从数据库(或者其他的数据源)收集原始的数据,然后建立相应的索引。
searchd则是通过读取indexer建立的索引来响应客户端的请求。
2、sphinx工作前提:配置文件修改
a、需要让其获取数据源从何而来(即:配置source信息)
b、建立索引,对数据源的哪部分数据进行索引等详细信息(即:indexer的所有信息)
c、执行indexer生产索引,最用才启用searchd服务
3、应用主要是通过api接口实现,支持php、perl、python及ruby等语言调用。
二、系统环境:
最好使用中文环境utf8
locale查看
修改/etc/profile 文件添加 export LC_ALL=zh.CN-UTF8
确认autoconf、automake安装可执行下
autoconf
automake
三、软件编译:
1
wget -c?http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.13.
tar
.gz
2
tar
?zxvf coreseek-3.2.13.
tar
.gz
3
cd
?coreseek-3.2.13/mmseg-3.2.13
4
./configure --prefix=/usr/
local
/mmseg
5
make
?&&?
make
?install
##中文分词测试,如果显示不正常,请检查当前环境下的locale和UTF-8中文字符显示设置
1
/usr/
local
/mmseg/bin/mmseg -d /usr/
local
/mmseg/etc src/t1.txt
根据需要编译:
1
#只支持xml源数据源
2
./configure --prefix=/usr/
local
/coreseek --without-python --without-mysql --with-mmseg --with-mmseg-includes=/usr/
local
/mmseg/include/mmseg/ --with-mmseg-libs=/usr/
local
/mmseg/lib/
3
make
?&&?
make
?install
4
#执行测试
5
/usr/
local
/coreseek/bin/indexer -c /usr/
local
/coreseek/etc/sphinx-min.conf.dist
6
#支持Mysql数据源
7
./configure --prefix=/usr/
local
/coreseek --with-mmseg=/usr/
local
/mmseg --with-mmseg-includes=/usr/
local
/mmseg/include/mmseg/ --with-mmseg-libs=/usr/
local
/mmseg/lib/ --with-mysql=/usr/
local
/mysql --with-mysql-includes=/usr/
local
/mysql/include/mysql/ --with-mysql-libs=/usr/
local
/mysql/lib/mysql/
8
make
?&&?
make
?install
可能遇到问题处理:
1、提示config.status: error: cannot find input file: src/Makefile.in
执行以下命令
1
aclocal
2
libtoolize --force
3
automake --add-missing
4
autoconf
5
autoheader
6
make
?clean
注:个人只运行下autoconf及automake即通过
2、Linux环境下,如遇到pthread问题,请先直接执行以下指令在进行configure前:
1
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/
local
/lib
2
export
?LD_LIBRARY_PATH
3、如果出现undefined reference to `libiconv’的类似错误,可以按照如下方法处理:
方法一:(Linux使用)
直接执行:export LIBS=”-liconv”
然后再次configure后,进行编译安装
方法二:
首先configure,然后vim src/makefile
在其中搜索lexpat,在其后加上 -liconv
修改后该行应该为:-lexpat -liconv -L/usr/local/lib
然后再次make
方法三:
#首先configure,然后vim config/config.h
在其中搜索USE_LIBICONV,将其后的1修改为0
然后再次make
四、文件配置:(/usr/local/coreseek/etc/csft.conf)
a、数据源(这里以mysql数据为例 也可支持xml方式)
01
source
?sphinx
02
{
03
sql_host = 192.168.1.100???
# mysql服务器ip
04
sql_user = sphinx???????
# mysql用户名
05
sql_pass = sphinx???????
# mysql密码
06
sql_db = sphinx?????
# mysql数据库名
07
type
?= mysql????????????
# 数据源类型
08
sql_port= 3306??????????
# optional, default is 3306
09
sql_query_pre= SET SESSION query_cache_type=OFF
10
sql_query_pre= SET NAMES utf8;
11
sql_query = SELECT * FROM documents WHERE?
id
=$
id
????# 具体数据列
12
}
b、索引任务:
01
index sphinx_test
02
{
03
source
???= sphinx
04
path?? = /usr/
local
/coreseek/var/data/sphinx
05
docinfo?? = extern
06
mlock?? = 0
07
morphology?? = none
08
stopwords?? =
09
min_word_len? = 1
10
charset_type? = utf-8
11
# 简单分词,只支持0和1,如果要搜索中文,请指定为1
12
ngram_len??? = 1
13
# 需要分词的字符,如果要搜索中文,去掉前面的注释
14
min_prefix_len? = 0
15
min_infix_len? = 1
16
}
c、搜索服务配置(基本保持默认即可)
01
searchd
02
{
03
port??????????????????????????? = 9312
04
log???????????????????????????? = /usr/
local
/coreseek/var/log/searchd.log
05
query_log?????????????????????? = /usr/
local
/coreseek/var/log/query.log
06
read_timeout??????????????????? = 5
07
max_children??????????????????? = 30
08
pid_file??????????????????????? = /usr/
local
/coreseek/var/log/searchd.pid
09
max_matches???????????????????? = 3000
10
seamless_rotate???????????????? = 1
11
preopen_indexes???????????????? = 0
12
unlink_old????????????????????? = 1
13
}
五、服务启动:
执行indexer生成索引:
1
/usr/
local
/coreseek/bin/indexer --rotate sphinx_test??
#只对sphinx_test索引任务
2
或
3
/usr/
local
/coreseek/bin/indexer --all --rotate??
# 针对所有索引任务
可能会出现数据库连接失败错误:
1
/usr/
local
/coreseek/bin/indexer sphinx_test --rotate
2
/usr/
local
/coreseek/bin/indexer: error?
while
?loading shared libraries: libmysqlclient.so.15: cannot
open
?shared object?
file
: No such?
file
?or directory
3
#先确认下libmysqlclient.so.15是否存在
4
ldd /usr/
local
/coreseek/bin/indexer
5
libmysqlclient.so.15 => not found
解决措施:
1
vim /etc/ld.so.conf
2
/usr/
local
/mysql/lib/mysql/?
#最后一行添加
3
[root@localhost etc]
# ldconfig
运行搜索服务searchd:
1
/usr/
local
/coreseek/bin/searchd &
六、应用:
API接口程序调用
?