sphinx+coreseek创建中文分词索引

 

一:安装sphinx步骤如下:

下载sphinx最新的2.2.11版本
cd /opt/sphinx
wget 下载地址
tar xzvf sphinx-2.2.11-release.tar.gz 
cd /opt/sphinx/sphinx-2.2.11-release
./configure --prefix=/opt/soft_install/sphinx/ --with-mysql=/usr/local/mysql
make && make install

安装成功后,会在目录:ls -lht /opt/soft_install/sphinx/下有四个文件夹
[root@XL_Php_Mysql sphinx-2.2.11-release]# ls -lht /opt/soft_install/sphinx/
总用量 16K
drwxr-xr-x 4 root root 4.0K 7月  22 12:05 var
drwxr-xr-x 2 root root 4.0K 7月  22 12:05 etc
drwxr-xr-x 3 root root 4.0K 7月  22 12:05 share
drwxr-xr-x 2 root root 4.0K 7月  22 12:05 bin

进入etc目录,拷贝配置文件, cp  sphinx-min.conf.dist  sphinx.conf  (这里不拷贝sphinx.conf.dist ,因为这文件只是比前者多了一堆注释)

其实只需要安装coreseek即可,不需要安装sphinx。


安装coreseek
首先下载软件,打开 官网 coreseek.cn(不过该网站已经打不开了,只能去其他地方下载,我是从csdn上下的,花了5积分,好心疼)
下载coreseek-4.1-beta.tar.gz(csdn下载)
cd /opt/coreseek
wget 下载地址
tar xzvf coreseek-4.1-beta.tar.gz
里有3个文件夹 一个是mmseg中文分词包 一个是csft(其实就是sphinx)包,一个是测试包testpack,只需安装前两个即可。

创建安装目录:
mkdir /opt/soft_install/coreseek

返回coreseek mmseg目录,开始首先安装mmseg
cd /opt/coreseek/coreseek-4.1-beta/mmseg-3.2.14/
首先安装mmseg中文分词
./configure --prefix=/opt/soft_install/coreseek/mmseg

编译时可能会报错config.status: error: cannot find input file: src/Makefile.in
通过automake来解决
首先检查是否安装了libtool如果没有 
yum -y install libtool
automake
如果automake报错 原因可能是下列
Libtool library used but `LIBTOOL' is undefined
The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
to `configure.ac' and run `aclocal' and `autoconf' again.
If `AC_PROG_LIBTOOL' is in `configure.ac', make sure
its definition is in aclocal's search path.

如果以上步骤都没成功,那么试下以下办法(把下面的命令都执行一遍,就好了)
aclocal
libtoolize -f (等于libtoolize --force)
automake -a (等于automake -add-missing)
autoconf
autoheader
make clean

执行完上述语句后,继续执行安装命令:
./configure --prefix=/opt/soft_install/coreseek/mmseg
此时会出现安装成功的命令显示:
------------------------------------------------------------------------
Configuration:

  Source code location:       .
  Compiler:                   gcc
  Compiler flags:             -g -O2
  Host System Type:           x86_64-redhat-linux-gnu
  Install path:               /opt/soft_install/coreseek/mmseg

  See config.h for further configuration information.
------------------------------------------------------------------------

运行安装命令:
make && make install

运行结束后,在安装目录:/opt/soft_install/coreseek/mmseg/会有四个文件产生:
[root@XL_Php_Mysql mmseg-3.2.14]# ls -lht /opt/soft_install/coreseek/mmseg/
总用量 16K
drwxr-xr-x 2 root root 4.0K 7月  22 12:31 etc
drwxr-xr-x 3 root root 4.0K 7月  22 12:31 include
drwxr-xr-x 2 root root 4.0K 7月  22 12:31 bin
drwxr-xr-x 2 root root 4.0K 7月  22 12:31 lib
测试是否安装成功:
/opt/soft_install/coreseek/mmseg/bin/mmseg -d /opt/soft_install/coreseek/mmseg/etc/ /opt/coreseek/coreseek-4.1-beta/mmseg-3.2.14/src/t1.txt

接着继续安装csft:
进入原码目录:
cd /opt/coreseek/coreseek-4.1-beta/csft-4.1
sh buildconf.sh
./configure --prefix=/opt/soft_install/coreseek/csft --with-mysql=/usr/local/mysql --with-mmseg=/opt/soft_install/coreseek/mmseg --with-mmseg-includes=/opt/soft_install/coreseek/mmseg/include/mmseg/ --with-mmseg-libs=/opt/soft_install/coreseek/mmseg/lib/

make && make install

安装成功后,在安装目录下有四个目录:
[root@XL_Php_Mysql coreseek]# ls -lht /opt/soft_install/coreseek/csft/
总用量 16K
drwxr-xr-x 4 root root 4.0K 7月  22 12:43 var
drwxr-xr-x 2 root root 4.0K 7月  22 12:43 etc
drwxr-xr-x 3 root root 4.0K 7月  22 12:43 share
drwxr-xr-x 2 root root 4.0K 7月  22 12:43 bin

安装完毕后 注意 coreseek 中的配置文件也是csft.conf 而不是 sphinx.conf
cd /opt/soft_install/coreseek/csft/etc/
cp sphinx.conf.dist csft.conf
vim csft.conf

测试是否安装成功
/opt/soft_install/coreseek/csft/bin/indexer -c /opt/soft_install/coreseek/csft/etc/csft.conf 
如果出现报错:/opt/soft_install/coreseek/csft/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
则需要将文件:
32位系统:ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so.18
64位系统:ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so.18


配置、测试mysql数据源搜索
cp /opt/coreseek/coreseek-4.1-beta/testpack/etc/csft_mysql.conf /opt/soft_install/coreseek/csft/etc/
[root@XL_Php_Mysql testpack]# ls -lht /opt/soft_install/coreseek/csft/etc/
总用量 68K
-rwxr-xr-x 1 root root 2.8K 7月  22 15:42 csft_mysql.conf
-rw-r--r-- 1 root root  26K 7月  22 12:43 csft.conf
-rw-r--r-- 1 root root  903 7月  22 12:43 example.sql
-rw-r--r-- 1 root root  26K 7月  22 12:43 sphinx.conf.dist
-rw-r--r-- 1 root root 1.2K 7月  22 12:43 sphinx-min.conf.dist

mysql -uroot -p test < /opt/coreseek/coreseek-4.1-beta/testpack/var/test/documents.sql 
创建索引数据库账户
mysql> grant all privileges on test.* to sphinxdbuser@"%" identified by "sphinx07test";
mysql> grant all privileges on recruitment_system.* to sphinxdbuser@"%" identified by "sphinx07test";
mysql> flush privileges;

5.2 启动搜索服务
启动搜索服务,这里选择后台运行的方式
# /opt/soft_install/coreseek/csft/bin/indexer -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --all
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf
以在log中记录每个查询的io和cpu状态的方式启动搜索服务
# /opt/soft_install/coreseek/csft/bin/searchd  --iostats --cpustats -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf

停止搜索服务
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --stop

查看搜索服务状态
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --status

5.3 本机搜索测试
# /opt/soft_install/coreseek/csft/bin/search -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf -a 百度成立

停止mysql,观察以上本机搜索测试是否正常
# /etc/init.d/mysqld stop

启动mysql,观察以上本机搜索测试是否正常
# /etc/init.d/mysqld start

5.4 异机php客户端api调用测试
API路径:/opt/coreseek/coreseek-4.1-beta/testpack/api/

拷贝test.php 和sphinxapi.php到支持php环境的机器,然后修改数据库地址,账号,密码等配置,测试如下:

# php test.php  中国  
Query '中国 ' retrieved 1 of 1 matches in 0.016 sec.
Query stats:
    '中国' found 17 times in 1 documents


运行时可能会出现错误:
Warning: assert() has been disabled for security reasons in /opt/test_coreseek/sphinxapi.php on line 182
则修改:
vi /etc/php.ini 
disable_functions = 该列去除assert,
重启php-fpm
/etc/init.d/php-fpm restart
再次运行即可。


 

转载于:https://my.oschina.net/u/435872/blog/1489067

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值