Sphinx以及coreseek的安装及使用
检索结构 php -> sphinx -> mysql 非结构化数据又叫全文数据,非固定长度字段例如文章标题搜索这类适用sphinx全文数据搜索: 1 顺序扫描 : 如like查找 2 索引扫描 : 把非结构化数据中的内容提取出来一部分重新组织,这部分数据就叫做索引全文检索分为两个过程 1.创建索引 2.搜索索引创建索引: sphinx通过语言处理组件会把搜索语句中的标点符号,语气助词给过滤掉,然后处理完毕后会 分析出一些词语,传给索引组件,然后排序去除重复词语.搜索索引: 搜索关键字 提交 -> sphinx 分析出文档ID -> mysql通过ID查询数据并返回中文分词需要coreseek coreseek 支持中文的全文检索引擎sphinx的安装 下载源码包 进行源码安装 ./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql make && make installsphinx 中重要的三个命令(bin目录下) Indexer 创建索引命令 Searchd 启动进程命令 Search 命令行搜索命令配置sphinx cd /usr/local/sphinx/etc cp sphinx.conf.dist sphinx.conf vi sphinx.conf配置文件 名为main的主数据源:source main{} 继承名为main的增量数据源:source delta:main{} 名为main的主索引:index main{} 继承名为main的增量索引:index delta:main{} 分布式索引:index dist1{} 索引器:indexer{} 服务进程:searchd{}修改配置文件中主数据源的mysql配置,测试环境的数据源名为main,假设mysql中test有张表叫post source main {# data source type. mandatory, no default value# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbctype = mysql####################################################################### SQL settings (for 'mysql' and 'pgsql' types)###################################################################### some straightforward parameters for SQL source typessql_host = localhostsql_user = rootsql_pass = adminsql_db = testsql_port = 3306 # optional, default is 3306sql_sock = /tmp/mysqld.sock #如果是linux下需要开启,指定sock文件sql_query_pre = SET NAMES utf8 sql_query_pre = SET SESSION query_cache_type=OFF #关闭缓存# main document fetch query# mandatory, integer document ID field MUST be the first selected columnsql_query = \ #获取数据的sql语句SELECT id,title,content FROM post#sql_attr_uint = group_id #对排序字段进行注释#sql_attr_timestamp = date_added #对排序字段进行注释sql_query_info = SELECT * FROM post WHERE id=$id} 注释掉所有增量数据源,修改主索引index main {source = main# index files path and file name, without extension# mandatory, path must be writable, extensions will be auto-appendedpath = /usr/local/sphinx/var/data/maindocinfo = externmlock = 0morphology = none# default is 1 (index everything)min_word_len = 1# charset encoding type# optional, default is 'sbcs'# known types are 'sbcs' (Single Byte CharSet) and 'utf-8'charset_type = utf-8# 'utf-8' default value is# charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F}注释掉所有的增量索引和分布式索引配置完成后,创建索引 命令 indexer -c 指定配置文件 --all 对所有索引重新编制索引 --rotate 用于轮换索引,主要是在不停止服务的时候,增加索引 --merge 合并索引 /usr/local/sphinx/sbin/indexer -c /usr/local/sphinx/etc/sphinx --all 如果报错./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory 解决方式:cp /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18测试 建立索引 [root@localhost bin]# ./indexer --all Sphinx 0.9.9-release (r2117) Copyright (c) 2001-2009, Andrew Aksyonoffusing config file '/usr/local/sphinx/etc/sphinx.conf'... indexing index 'main'... collected 2 docs, 0.0 MB sorted 0.0 Mhits, 100.0% done total 2 docs, 47 bytes total 0.033 sec, 1414 bytes/sec, 60.21 docs/sec total 1 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg total 5 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg搜索 [root@localhost bin]# ./search linux1 Sphinx 0.9.9-release (r2117) Copyright (c) 2001-2009, Andrew Aksyonoffusing config file '/usr/local/sphinx/etc/sphinx.conf'... index 'main': query 'linux1 ': returned 1 matches of 1 total in 0.000 secdisplaying matches: 1. document=1, weight=1id=1title=linux1content=salflsdkjsdgldswords: 1. 'linux1': 1 documents, 1 hitssphinx相当于把数据库数据索引静态化到本地 来加快查询速度 避免消耗数据库,给数据库给降压,当数据更新的时候,需要重新indexer --all 或者用 indexer main重建所有索引 才会搜出新的数据安装CORESEEKcoreseek里有2个文件夹 一个是mmseg中文分词包 还有一个是csft(其实就是sphinx)包 都要安装首先安装mmseg中文分词 ./configure --prefix=/usr/local/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是个扫描程序, 负责扫描configure.ac中所有的宏定义并展开, 上面产生的原因就是找不到LIBTOOL宏的定义之处造成的.原因就是aclocal与libtool没有安装在一个相同目录下面aclocal是去默认 安装目录 /usr/share/aclocal下面搜索所有的.m4文件找所定义的宏,但是由于安装了多个aclocal,可能aclocal目录不存在,实际目录为/usr/share/aclocal1.10等, 这就造成了aclocal找不到m4文件的情况, 解决办法就是将文件夹aclocal1.10重命名为aclocal.或者显示指定路径 aclocal -I /usr/share/aclocal1.10 -I /usr/share/libtool/m4 --install 或者把/usr/share/libtool/m4下面的文件都copy至/usr/share/aclocal1.10中. 本人的机器上是/usr/share/下有2个文件夹 一个是aclocal,一个是aclocal-1.11,首先将aclocal的所有文件拷贝到aclocal-1.11下 cp -R /user/share/aclocal/* /usr/share/aclocal-1.11/然后重新运行aclocal和autoconf aclocal && autoconf 最后再次运行automake automake然后继续mmseg的安装 ./configure --prefix=/usr/local/mmseg make && make install如果make 报错 There is an easy fix when you get such messages as "X--tag=CXX: command not found". Just type: export echo=echo And try again.所以输入 export echo=echo 然后再次运行安装 make && make install安装csft ./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ make && make install 安装完毕后 注意 coreseek 中的配置文件也是csft.conf 而不是 sphinx.conf cd /usr/local/coreseek/etc cp sphinx.conf.dist csft.conf vim csft.conf 有些配置改动如下其他配置内容如上文的sphinx.conf 在索引源中注释掉txt index main{#stopwords = G:\data\stopwords.txt#wordforms =G:\data\wordforms.txt#exceptions =/data/exceptions.txt #charset_type = sbcs#添加下面2行 意思是把中文分词加入到配置文件中char_type = zh_cn.utf-8charset_dictpath =/usr/local/mmseg/etc/ #你安装mmseg的目录 }保存配置 建立索引 cd /usr/local/coreseek/bin ./indexer --all ./search 中文词缀如何用php去使用sphinx Sphinx集成到php程序中有两种方式 1.Sphinx php 模块(这次我们选择使用的方式) 2.Sphinx api 类(位于coreseek源码包里的csft里的api文件夹里有一个sphinxapi.php,使用的时候包含这个php文件即可)我们要使用sphinx需要做以下几件事: 1.首先要有数据 2.建立sphinx配置文件 3.生成索引 4,启动searchd 服务进程,并开启端口9312 5.用php客户程序去链接sphinx服务/usr/local/coreseek/bin/searchd 启动进程命令 searchd -c 指定配置文件 --stop 停止服务 --pidfile 显示指定pid文件 -p 指定端口(默认9312) 注意:这里启动的服务是searchd使用php sphinx的模块 下载 sphinx-1.1.0.tgztar zvxf sphinx-1.1.0.tgz cd sphinx-1.1.0 /usr/local/php/bin/phpize #用于生成一个configure的脚本 进入coreseek源码包的csft/api/libsphinxclent 目录下执行configure ./configure make && make install 进入sphinx-1.1.0.gzt的源码包目录下 执行configure用于生成so 的shpinx模块 ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-sphinx make && make install 安装成功后会有提示 Build complete. Don't forget to run 'make test'.Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ (这个目录是sphinx.so所在的目录)然后我们编辑php的ini文件 在extension中加入 extension=sphinx.so然后重启nginx和php的服务 最后打印一下phpinfo 查看sphinx是否开启成功 如果成功开启 就可以使用php手册里的sphinx的方法和代码了
Sphinx以及coreseek的安装及使用相关推荐
- Linux下coreseek环境安装 、mysql数据源、sphinx扩展安装及php调用
一.安装m4-1.4.13.autoconf-2.64.automake-1.11.libtool-2.2.6 下载安装m4-1.4.13.autoconf-2.64.automake-1.11.li ...
- Sphinx到Coreseek安装全解
此次采用的是CentOS6.5 32位 如有出入,请参阅相关配置手册说明 --@Author云天河Blog Sphinx部分 简介 Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,Po ...
- sphinx和coreseek
sphinx是国外的一款搜索软件. coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文. Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本 ...
- 基于php的Sphinx以及coreseek的全文搜索,中文分词的使用(一)
基于php的Sphinx以及coreseek的全文搜索,中文分词的使用(一) ##1.sphinx简介 1.什么是sphinx Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检 ...
- Sphinx在windows下安装使用
Sphinx 在 windows 下安装使用 前一阵子尝试使用了一下 Sphinx ,一个能够被各种语言 (PHP/Python/Ruby/etc) 方便调用的全文检索系统.网上的资料大多是在 lin ...
- php mmseg,coreseek+sphinx+mmseg中文分词安装
由于官网挂了,找资源 下载coreseek+sphinx+mmseg中文分词安装费了很多时间 开始是在github上一阵狂搜,找了几个都安装失败,后来在csdn上找到资源,一阵折腾之后安装成功 准备工 ...
- coreseek/sphinx CentOS6.4下安装
一.在CentOS6.4下安装coreseek之前需要预先安装以下软件 1.打开终端 输入 su 获取管理员权限 2.输入命令 yum install make gcc g++ gcc-c++ lib ...
- 基于Sphinx的中文全文检索引擎Coreseek的安装
按照Sphinx来进行全文检索,默认只支持按字拆分,如果要实现比较好的中文分词,可以使用基于libmmseg的引擎Coreseek. yum install g++ yum install gcc y ...
- Sphinx 之 Coreseek、Sphinx-for-chinaese、Sphinx+Scws 评测
http://www.wubiao.info/292 Sphinx是一个基于SQL的全文检索引擎:普遍使用于很多网站:但由于中英文的差异,其本身,对中文的支持并不好. 主要体现在对一段话断词:英文只需 ...
最新文章
- 时隔6年,“三巨头”再度联手,发布万字长文:深度学习将通往何方?
- 2.6 谷歌 Inception 网络简介-深度学习第四课《卷积神经网络》-Stanford吴恩达教授
- 深度学习(二十六)Network In Network学习笔记-ICLR 2014
- IsPostBack原理
- 【C#】VS2012+InstallShield2013制作软件更新包
- python开发多平台app_django下创建多个app并设置urls方法
- seaborn常用速查手册
- activity(工作流)初步学习记录
- 打印机简体打出繁体、乱码解决办法
- linux该如何备份多个分区文件格式,使用partimage 备份Linux 多格式分区
- Unity UV基于中心点旋转/缩放/位移 Shader
- j3455linux网卡不亮,J3455 ProxmoxVE v6.0-4 直通物理网卡教程
- 深入理解Java虚拟机—Java虚拟机内存
- sql函数DATEPART()与DATENAME()
- 使用云主机的5大好处?
- 九度OJ北京航空航天大学2008机试题题解
- python制作二维码_基于Python生成个性二维码过程详解
- RabbitMQ消息队列工作原理及集成使用
- 北京八达岭野生动物园伤人事件
- STM32F103芯片FSMC使用外扩SRAM芯片
热门文章
- php设置外键约束,关于php:禁用教义外键约束
- 计算机多媒体的应用 毕业论文,计算机多媒体技术(毕业论文)多媒体技术与应用.doc...
- linux怎么升级python2.7,linux升级python到2.7
- 报错,java.lang.NoSuchMethodException: java.awt.print.Pageable
- 2019年春计算机应用基础随堂作业,华南理工2019年《计算机应用基础》随堂练习 doc...
- 前端路由跳转丢失端口号_如何在应用架构中设计微前端方案 icestark
- bzoj2424 [HAOI2010]订货 费用流
- 2017.5.9 货车运输 思考记录
- 2017.4.25 解方程 思考记录
- 【英语学习】【Level 08】U01 Let's Read L6 Person of the year