coreseek中文搜索

来源:互联网 发布:mac豆沙色口红推荐 编辑:程序博客网 时间:2024/06/06 20:18

coreseek的安装和使用

 

准备软件包

coreseek-3.2.14.tar.gz  http://pan.baidu.com/s/1geNCFrd

 

其他汁源

coreseek中文索引-示例文件.zip  http://pan.baidu.com/s/1qYF3b68

sphinx配置文件详解.txt  http://pan.baidu.com/s/1c7OcSQ

 

1.安装组件

yum -y install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel

 

2.安装mmseg

$ cd /usr/local/tools/

$ tar xf coreseek-3.2.14.tar.gz

$ cd coreseek-3.2.14/mmseg-3.2.14

$./bootstrap

$./configure --prefix=/usr/local/mmseg

$ make && make install

 

3.安装coreseek

$ cd /usr/local/tools/coreseek-3.2.14/csft-3.2.14

$ sh buildconf.sh

$./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql

$ make && make install

 

4.修改配置文件, 导入测试数据

$ vi /etc/ld.so.conf

/usr/local/mysql/lib  ##新增一行

$ ldconfig

 

$ cd /usr/local/coreseek/etc

$ cp sphinx-min.conf.dist example.conf

##修改example的配置文件 (示例文件在压缩包内)

##导入example.sql的测试数据(示例文件在压缩包内)

$ echo "" > /usr/local/coreseek/var/log/searchd_example.pid  ##生成进程文件

 

5.开始测试

##启动服务

$ /usr/local/coreseek/bin/searchd --config  /usr/local/coreseek/etc/example.conf

using config file '/usr/local/coreseek/etc/example.conf'...

listening on all interfaces, port=9312

rotating index 'example': success

 

##重建索引

$ /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/example.conf --all --rotate

using config file '/usr/local/coreseek/etc/example.conf'...

indexing index 'example'...

collected 4 docs, 0.0 MB

sorted 0.0 Mhits, 100.0% done

total 4 docs, 193 bytes

total 0.016 sec, 11577 bytes/sec, 239.95 docs/sec

total 2 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg

total 7 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg

rotating indices: succesfully sent SIGHUP to searchd (pid=100199).

 

##停止服务

$ /usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/example.conf --stop

 

using config file '/usr/local/coreseek/etc/example.conf'...

stop: succesfully sent SIGTERM to pid 100199

 

##php端测试

$ cp /usr/local/tools/coreseek-3.2.14/testpack/api/sphinxapi.php /usr/local/httpd/htdocs/  ##复制sphinx类文件(示例文件在压缩包内)

vi /usr/local/httpd/htdocs/test.php  ##新建测试脚本(示例文件在压缩包内)

<?php

require_once('sphinxapi.php');

$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,"group_id DESC" ); // 设置排序

$s->SetArrayResult(true);//控制搜索结果集的返回格式

$res = $s->Query($keyword,'*');// 执行搜索查询

$res_list = $res['matches'];

echo "<pre>";

print_r($res_list);

?>

重启example的索引服务, 然后在浏览器访问: http://localhost/test.php

如果OK将会看到输出...

 

 

 

 

0 0
原创粉丝点击