淡水网站建设,健身器材 网站模版,大连住房和建设局网站,装修设计在线一、Sphinx的特性高速的建立索引(在当代CPU上#xff0c;峰值性能可达到10 MB/秒);高性能的搜索(在2 – 4GB 的文本数据上#xff0c;平均每次检索响应时间小于0.1秒);可处理海量数据(目前已知可以处理超过100 GB的文本数据, 在单一CPU的系统上可处理100 M 文档);提供了优秀的…一、Sphinx的特性高速的建立索引(在当代CPU上峰值性能可达到10 MB/秒);高性能的搜索(在2 – 4GB 的文本数据上平均每次检索响应时间小于0.1秒);可处理海量数据(目前已知可以处理超过100 GB的文本数据, 在单一CPU的系统上可处理100 M 文档);提供了优秀的相关度算法基于短语相似度和统计(BM25)的复合Ranking方法;支持分布式搜索;可作为MySQL的存储引擎提供搜索服务;支持布尔、短语、词语相似度等多种检索模式;文档支持多个全文检索字段(最大不超过32个);文档支持多个额外的属性信息(例如分组信息时间戳等);停止词查询;支持单一字节编码和UTF-8编码;原生的MySQL支持(同时支持MyISAM 和InnoDB );原生的PostgreSQL 支持.二、安装中文分词mmseg下载mmsegwget http://www.coreseek.com/uploads/sources/mmseg-0.7.3.tar.gz编译安装tar zxf mmseg-0.7.3.tar.gz cd mmseg-0.7.3./configure --prefix/usr/local/mmsegmake make installln -s /usr/local/mmseg/bin/mmseg /usr/bin/如果出现 make[2]: *** [UnigramCorpusReader.lo] Error 1报错,解决方法如下vim src/css/UnigramCorpusReader.cpp在23行加入#include 重新编译测试安装成功如下所示[rootiZ28bak61f3Z bin]#mmsegCoreseek COS(tm) MM Segment 1.0Copyright By Coreseek.com All Right Reserved.Usage: ./mmseg -u Unigram Dictionary-r Combine with -u, used a plain text build Unigram Dictionary, default Off-b Synonyms Dictionary-h print this help and exit三、编译安装配置 (MySQL 5.6.24)下载sphinxwget http://pkgs.fedoraproject.org/repo/pkgs/sphinx/sphinx-0.9.9.tar.gz/7b9b618cb9b378f949bb1b91ddcc4f54/sphinx-0.9.9.tar.gz编译安装sphinxtar zxf sphinx-0.9.9.tar.gzcd sphinx-0.9.9yum install python-devel./configure --prefix/usr/local/sphinx --with-mysql/usr/local/mysql/ --with-mysql-includes/usr/local/mysql/include/ --with-mysql-libs/usr/local/mysql/lib/ --with-mmseg-includes/usr/local/mmseg/include/mmseg --with-mmseg-libs/usr/local/mmseg/lib/ --with-mmsegmake make install配置sphinxcd /usr/local/sphinx/etc/cp sphinx.conf.dist sphinx.conf修改以下内容type mysqlsql_host localhostsql_user rootsql_pass ****sql_db testsql_port 3306四、建立索引创建一个test库导入 example.sql,进行测试mysql -uroot -p /usr/local/sphinx/etc/example.sql索引的建立方法:/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf test1test1为资源名称 不写为默认所有都建立索引,出现如下提示说明索引建立完成Sphinx 0.9.9-release (r2117)Copyright (c) 2001-2009, Andrew Aksyonoffusing config file /usr/local/sphinx/etc/sphinx.conf...indexing index test1...collected 4 docs, 0.0 MBsorted 0.0 Mhits, 100.0% donetotal 4 docs, 193 bytestotal 0.030 sec, 6256 bytes/sec, 129.67 docs/sectotal 2 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avgtotal 7 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg五、启动服务器开启/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf关闭/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf --stop通过search工具查询/usr/local/sphinx/bin/search --config /usr/local/sphinx/etc/sphinx.conf testSphinx 0.9.9-release (r2117)Copyright (c) 2001-2009, Andrew Aksyonoffusing config file /usr/local/sphinx/etc/sphinx.conf...index test1: query test : returned 3 matches of 3 total in 0.000 secdisplaying matches:1. document1, weight2, group_id1, date_addedWed Oct 14 15:01:39 2015id1group_id1group_id25date_added2015-10-14 15:01:39titletest onecontentthis is my test document number one. also checking search within phrases.2. document2, weight2, group_id1, date_addedWed Oct 14 15:01:39 2015id2group_id1group_id26date_added2015-10-14 15:01:39titletest twocontentthis is my test document number two3. document4, weight1, group_id2, date_addedWed Oct 14 15:01:39 2015id4group_id2group_id28date_added2015-10-14 15:01:39titledoc number fourcontentthis is to test groupswords:1. test: 3 documents, 5 hits六、sphinx 启动脚本vim /etc/init.d/sphinx#!/bin/bash# sphinx: Startup script for Sphinx search## chkconfig: 345 86 14# description: This is a daemon for high performance full text /# search of MySQL and PostgreSQL databases. /# See http://www.sphinxsearch.com/ for more info.## processname: searchd# pidfile: $sphinxlocation/var/log/searchd.pid# Source function library.. /etc/rc.d/init.d/functionsprocessnamesearchdservicenamesphinxusernamesphinxsphinxlocation/usr/local/sphinxpidfile$sphinxlocation/var/log/searchd.pidsearchd$sphinxlocation/bin/searchdRETVAL0PATH$PATH:$sphinxlocation/binstart() {echo -n $Starting Sphinx daemon: daemon --user$username --check $servicename $processnameRETVAL$?echo[ $RETVAL -eq 0 ] touch /var/lock/subsys/$servicename}stop() {echo -n $Stopping Sphinx daemon: $searchd --stop#killproc -p $pidfile $servicename -TERMRETVAL$?echoif [ $RETVAL -eq 0 ]; thenrm -f /var/lock/subsys/$servicenamerm -f $pidfilefi}# See how we were called.case $1 instart)start;;stop)stop;;status)status $processnameRETVAL$?;;restart)stopsleep 3start;;condrestart)if [ -f /var/lock/subsys/$servicename ]; thenstopsleep 3startfi;;*)echo $Usage: $0 {start|stop|status|restart|condrestart};;esacexit $RETVALchmod 755 /etc/init.d/sphinxchkconfig --add sphinxchkconfig --level 345 sphinx on #开机启动service sphinx start #运行service sphinx stop #停止service sphinx restart #重启service sphinx status #查看是否运行