搜索
首页数据库mysql教程【原创】用coreseek快速搭建sphinx中文分词搜索引擎

以下内容基于linux 系统。 yum -y install glibc-common libtool autoconf automake mysql-devel expat-devel#如果不安装这个 可能下面 sh buildconf.sh会报错!!!cd /data/srctar -xjf ../software/autoconf-2.64.tar.bz2cd autoconf-2.64/./configuremak

以下内容基于linux 系统。

yum -y install glibc-common libtool autoconf automake mysql-devel expat-devel
#如果不安装这个 可能下面 sh buildconf.sh会报错!!!
cd /data/src
tar -xjf ../software/autoconf-2.64.tar.bz2
cd autoconf-2.64/
./configure
make && make install
cd ../
cd /data/software
wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
cd /data/src
tar zxf ../software/coreseek-4.1-beta.tar.gz
cd coreseek-4.1-beta/mmseg-3.2.14
./bootstrap
./configure --prefix=/usr/local/mmseg3
make && make install
cd ../
cd /data/src/coreseek-4.1-beta/csft-4.1/
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/ --without-mysql
make && make install
cd ../
##测试mmseg分词,coreseek搜索(需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文)
cd testpack
cat var/test/test.xml    #此时应该正确显示中文
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
/usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索
#创建sphinx创建索引的脚本:
mkdir -p /data/sh/other

vi /data/sh/other/sphinx_update_index.sh

#!/bin/bash
CONFFILE=/usr/local/coreseek/etc/sphinx_index.conf
/bin/sed s#var\/data\/#var\/data2\/#g ${CONFFILE} > ${CONFFILE}.2
mkdir -p /usr/local/coreseek/var/data2
#/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all --rotate
/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all
pkill -9 searchd
sleep 4
/bin/rm -rf /usr/local/coreseek/var/data/
/bin/mv /usr/local/coreseek/var/data2/ /usr/local/coreseek/var/data/
sleep 2
/usr/local/coreseek/bin/searchd --config ${CONFFILE}

chmod 755 /data/sh/other/sphinx_update_index.sh

#配置sphinx索引参数配置

vi /usr/local/coreseek/etc/sphinx_index.conf

################################### PHPCMS ############################################
source cc_phpcms
{
	type = mysql
	sql_host = 172.26.11.75  #此处请改成您的真实配置
	sql_user = phpcms  #此处请改成您的真实配置
	sql_pass = 123456   #此处请改成您的真实配置
	sql_db = phpcms   #此处请改成您的真实配置
	sql_port= 3306  #此处请改成您的真实配置
	sql_query_pre = SET SESSION query_cache_type=OFF
	sql_query_pre = SET character_set_client = 'gbk'
	sql_query_pre = SET character_set_connection ='gbk'
	sql_query_pre = SET character_set_results ='utf8'
	sql_query = SELECT `id`,`catid`,`typeid`,`title`,`status`,`updatetime` from `i_news` #此处请改成您的真实配置
	sql_range_step          = 1000
	sql_attr_timestamp      = updatetime
	sql_attr_uint           = catid
	sql_attr_uint           = typeid
	sql_attr_uint           = status
	sql_query_post  =
	sql_ranged_throttle= 0
}
index cc_phpcms
{
	source   = cc_phpcms
	path   = /dev/shm/cc_phpcms   #放这里比较好,因为这里是linux的内存区!
	docinfo   = extern
	mlock   = 0
	enable_star            = 1
	morphology   = none
	stopwords   =
	min_word_len  = 1
	charset_dictpath = /usr/local/mmseg3/etc/   #注意此处
	charset_type        = zh_cn.utf-8           #注意此处
	html_strip = 1
	html_remove_elements = style, script
	html_index_attrs = img=alt,title; a=title;
}
#################################### SETTING ############################################
indexer
{
	mem_limit   = 300M
}
searchd
{
	# address    = 0.0.0.0
	#listen                  = 3312
	#listen                  = 9312
	#listen                  = 9306:mysql41
	port    = 3312
	log     = /usr/local/coreseek/var/log/searchd.log
	query_log   = /usr/local/coreseek/var/log/query.log
	read_timeout  = 5
	max_children  = 30
	pid_file   = /usr/local/coreseek/var/log/searchd.pid
	max_matches   = 1000
	seamless_rotate  = 1
}

#接下来实现数据源支持:让sphinx支持MySQL数据源

yum -y install mysql-devel libxml2-devel expat-devel
cd /data/src/coreseek-4.1-beta/csft-4.1/
make clean
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
make && make install
cd ../

##如果出现错误提示:“ERROR: cannot find MySQL include files…….To disable MySQL support, use –without-mysql option.“,可按照如下方法处理:
##请找到头文件mysql.h所在的目录,一般是/usr/local/mysql/include,请替换为实际的
##请找到库文件libmysqlclient.a所在的目录,一般是/usr/local/mysql/lib,请替换为实际的
##configure参数加上:–with-mysql-includes=/usr/local/mysql/include –with-mysql-libs=/usr/local/mysql/lib,执行后,重新编译安装
#跑sphinx服务脚本
/data/sh/other/sphinx_update_index.sh

好了,如果一切正常,将会顺利看到创建索引的信息如下:
112 【原创】用coreseek快速搭建sphinx中文分词搜索引擎

下面写一段php代码进行测试(基于sphinx php 的api方式):

		$page = (int)$_GET['page'];
		$page = ($page==0)?1:$page;
		$perpage = 200;
		$start = ($page -1) * $perpage;
		$keyword = urldecode($_GET['key']);
		require_once (S_ROOT . './api/sphinxapi.php');//请改成您的真实路径
 		$groupby = "";
		$groupsort = "@group desc";
		$filter = "fieldid";
		$filtervals = array ();
		$distinct = "";
		$sortby = "";
		$cl = new SphinxClient();
		$cl->SetServer("localhost", 3312);
		$cl->SetWeights(array (
				100,
				1
		));
		$cl->SetMatchMode(SPH_MATCH_ANY);
		if (count($filtervals)) {
				$cl->SetFilter($filter, $filtervals);
		}
		if ($groupby) {
				$cl->SetGroupBy($groupby, SPH_GROUPBY_ATTR, $groupsort);
		}
		$order = 1;
		if ($order == 0) { //按时间倒序
				$cl->SetSortMode(SPH_SORT_ATTR_DESC, "inputtime");
		}
		elseif ($order == 1) { //按相关度排序
				$cl->SetSortMode(SPH_SORT_RELEVANCE);
		}
		if ($distinct) {
				$cl->SetGroupDistinct($distinct);
		}
		$cl->SetLimits($start, $perpage, ($limit > 1000) ? $limit : 1000);
		$cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
		$cl->SetArrayResult(true);
		$res = $cl->Query($keyword, 'cc_phpcms');
		print_r($res);die;

上面的php代码没有做输入的字符过滤,这个请按自己的需要加上。
另外,
/data/sh/other/sphinx_update_index.sh 跑了一次后,

vi /data/sh/other/sphinx_update_index.sh

#/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all --rotate
/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all

变成

/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all --rotate
#/usr/local/coreseek/bin/indexer --config ${CONFFILE}.2 --all

也就是将注释调换,这样以后就可以设定个定时计划跑/data/sh/other/sphinx_update_index.sh 脚本了,
跑了/sphinx_update_index.sh 脚本后,自动会用–rotate的方式重建索引,也就是说新增加的内容也将会被索引到了。

当然,最好的方法还是做个实时索引的配置,下一篇将会重点介绍sphinx的实时索引功能!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在MySQL中使用视图的局限性是什么?在MySQL中使用视图的局限性是什么?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

确保您的MySQL数据库:添加用户并授予特权确保您的MySQL数据库:添加用户并授予特权May 14, 2025 am 12:09 AM

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素会影响我可以在MySQL中使用的触发器数量?哪些因素会影响我可以在MySQL中使用的触发器数量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存储斑点安全吗?mysql:存储斑点安全吗?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通过PHP Web界面添加用户mySQL:通过PHP Web界面添加用户May 14, 2025 am 12:04 AM

通过PHP网页界面添加MySQL用户可以使用MySQLi扩展。步骤如下:1.连接MySQL数据库,使用MySQLi扩展。2.创建用户,使用CREATEUSER语句,并使用PASSWORD()函数加密密码。3.防止SQL注入,使用mysqli_real_escape_string()函数处理用户输入。4.为新用户分配权限,使用GRANT语句。

mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中