coreseek和xunsearch的使用

环境Centos7

安装基础依赖库

yum -y install make gcc gcc-c++ libtool autoconf automake

官网下载xunsearch

wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2

解压

tar -jxvf xunsearch-full-latest.tar.bz2

解压失败请安装

yum install -y bzip2

进入解压目录

sh setup.sh

//出现提示 有默认安装路径 不改直接按回车

启动xunsearch

服务器和SDK不在一台机器上 使用第三种启动

bin/xs-ctl.sh -b local start    // 监听在本地回环地址 127.0.0.1 上
bin/xs-ctl.sh -b inet start     // 监听在所有本地 IP 地址上
bin/xs-ctl.sh -b a.b.c.d start  // 监听在指定 IP 上 我是不在同一服务器上,因此我选择这一种(bin/xs-ctl.sh -b 195.241.23.32 start)
bin/xs-ctl.sh -b unix start     // 分别监听在 tmp/indexd.sock 和 tmp/searchd.sock

项目配置

 在sdk/php/app目录下

配置内容详解

project.name = demo  //项目名称
project.default_charset = utf-8  //设置字符集
server.index = 8383   //索引端口
server.search = 8384  //搜索端口

[pid]      //字段
type = id    //字段类型   默认字符型 numeric(数值型) date(日期型) id(主键型) title(标题行) body(内容型) ps:每个项目必须有个主键型的字段
index  = self   //索引类型  self(字段索引)  mixed(混合区索引) both(字段和混合区)
tokenizer =default  //该字段的分词方式   full none splite xlen xstep
cutlen  = n //截取长度
phrase =  yes  //精度搜索

使用util/Index.php 导入MySQL数据 格式如下

util/Indexer.php  项目名   --source=mysql://mysql用户名:访问密码@ip地址:端口号/databaseName  --sql='select  字段名   from  表名'    --clean 或者  --rebuild

--clean 清空重建  --rebuild重建   ps:配置文件字段必须和数据库字段一致

php util/Indexer.php --source=mysql://root:root@192.168.88.170/easybee --sql="SELECT id,title,content from easy_article" --project=demo --rebuild


使用

重点使用

引入类文件

$xs = new XS('dome');

$index = $xs->index;//获取索引对象

$search = $xs->search;//获取搜索对象 

然后参考手册去找高亮处理


coreseek4.1的使用

环境依赖 

yum -y install automake libtool 

解压 coreseek包  内部有mmse  csf  

先安装mmseg

cd mmseg-3.2.14/

./bootstrap

automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
警告不处理

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

make && make install

安装sphinx服务

cd ../csft-3.2.14

sh buildconf.sh

出现错误 automake: warnings are treated as errors

总体意思是: archiver requires ‘AM_PROG_AR‘ in ‘configure.ac‘

解决办法:在 csft-4.1/configure.ac 文件中,查找:

AC_PROG_RANLIB

后面加上

AM_PROG_AR

最终格式为:AC_PROG_RANLIB AM_PROG_AR

再次执行 sh buildconf.sh 出现错误 configure.ac:61: error: required file 'config/ar-lib' not found configure.ac:61: 'automake --add-missing' can install 'ar-lib'

运行 automake --add-missing

再次执行 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=mysql路径 --with-python

make && make install

编译时出错 ‘ExprEval’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

处理方法:

修改vim src/sphinxexpr.cpp

把所有 T val = ExprEval ( this->m_pArg, tMatch ); 修改为-> T val = this->ExprEval ( this->m_pArg, tMatch );

再次执行make && make install

错误 :
In file included from sphinxstd.cpp:24:0:

py_layer.h:16:27: fatal error: Python.h: No such file or directory

#include <Python.h>

这是由于缺少了python环境的devel支持包

解决办法:yum install python-devel


启动服务及测试

cd ../testpack/

##如要启动搜索服务,请使用

/usr/local/coreseek/bin/searchd -c etc/csft.conf(注意-c后面是相对路径)

##如要停止搜索服务,请使用

/usr/local/coreseek/bin/searchd -c etc/csft.conf --stop


/usr/local/src/coreseek-3.2.14/testpack/etc/pysource

支持python选项,会有一个

 

发现sphinx indexer依赖库ibmysqlclient.so.18找不到,通过编辑此文件来修复这个错误 /etc/ld.so.conf
vi /etc/ld.so.conf
将下面这句加到文件到尾部,并保存文件
/usr/local/mysql/lib
然后运行下面这个命令即可

ldconfig


php7不支持 类名作为构造函数 把接口文件更改成 __construct

 

sphinx 高亮显示

$sphinx->buildExcerpts($row,$index,$keyword,[$option]);

 

及时索引

创建 计数表

create table sph_counter (
->id int not null primary_key auto_increament,
->maxid int not null);

修改 sphinx 配置

创建主索引源 继承索引源 主索引 继承索引


主索引源
sql_query_pre = sql 语句 #在执行sql前执行的操作
sql_query_pre = set session_cache=off 关闭缓存
sql_query_pre = replace into 表 select 1 ,max(id) form 索引表 #更改计数器
sql_query = sql where id <= (select maxid from sph_cont where id =1);

 

#定义主索引源
source main
{
sql_query_pre = sql 语句 #在执行sql前执行的操作
sql_query_pre = replace into 表 select 1 ,max(id) form 索引表 #更改计数器
sql_query = sql where id <= (select maxid from sph_cont where id =1);
}

#增量索引源
source add : mian
{
sql_query = sql where id >(select maxid from sph_cont where id =1);
}

#主索引
index main
{
aource main
}
#增量索引
index add : mian
{
source add
}

建立
main.sh 主索引执行程序
add.sh 增索引执行程序

格式
#!/bin/bash
#main.sh
/usr/local/depends/coreseek/bin/indexer main --rotate >> /usr/local/depends/coreseek/var/log/main.log

创建计时器
crintab -e

*/5 * * * * 路径/add.sh 每个五分中 建立 一个增量索引
00 03 * * * 路径/main.sh 每天三点 全站索引一次





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值