<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I@laoer.com &#187; Sphinx</title>
	<atom:link href="http://i.laoer.com/tag/sphinx/feed" rel="self" type="application/rss+xml" />
	<link>http://i.laoer.com</link>
	<description>技术、生活、感悟 -- Laoer的博客</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:03:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sphinx+Mysql初使用体验</title>
		<link>http://i.laoer.com/sphinx-mysql.html</link>
		<comments>http://i.laoer.com/sphinx-mysql.html#comments</comments>
		<pubDate>Fri, 08 May 2009 06:44:02 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Sphinx]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=311</guid>
		<description><![CDATA[应用越来越多的需要全文搜索技术来支撑，在Java中可以使用Lucene，一个非常优秀的引擎，在Hibernate中也整合了Lucene来做检索，但在使用PHP的过程中迫切需要找一个优秀的全文搜索引擎（虽然也可以把PHP和Lucene结合起来使用，但有些另类，有些生产环境也不能同时支持），以前在网上看到一些Sphinx的文章，一直没有实践，昨天我就花了一天的时间，配置测试了一下Sphinx。 由于我的PHP没有编译Sphinx模块，所以我主要是配置Sphinx+Mysql，在Mysql上测试全文搜索的效果，Mysql、Sphinx、中文分词的编译安装过程不详述，下面两篇文章挺好，安装时可以参考 Mysql+sphinx+中文分词简介 基于Sphinx+MySQL的千万级数据全文检索（搜索引擎）架构设计 我的编译安装过程没有遇到什么麻烦，就是编译Mysql的时候比较长，而且要注意把Innodb的引擎编译进去，我的Mysql编译参数如下 ./configure &#8211;with-plugins=sphinx,innobase,heap &#8211;prefix=/usr/local/mysql &#8211;enable-assembler &#8211;with-charset=utf8 &#8211;with-extra-charsets=all &#8211;enable-thread-safe-client &#8211;with-big-tables &#8211;with-readline &#8211;with-ssl &#8211;with-embedded-server &#8211;enable-local-infile 比较奇怪的是innodb是支持了，heap不支持，这个问题下次再研究。 通过编译Mysql，使Mysql支持了Sphinx存储引擎，试了一下Sphinx的例子，成功搜索到了数据，如果我们要对自己的数据做索引，就要研究一下Sphinx的配置文件了。 Sphinx的配置文件在其安装目录下的etc目录下，你可以参考其例子的sphinx.conf创建自己的配置文件，在sphinx里有主要要配置的有两大块，一部分是source（数据源），另一部分是index（索引），source里面定义了连接数据库的参数，取得源数据的SQL，也就是你要索引的数据的取得 SQL（Sphinx是支持不同数据源的，我这里只测试SQL），source可以有继承关系，继承的source可以用来做取得增量数据，index里面定义了使用哪个source，index存放的路径、字符集、辞典等等，index也可以继承，继承的index用来做增量索引。由此可见source 和index都是根据你的需要配置的，可以取得多个数据源的数据，可以建立多个索引。 增量索引的小困惑，我在数据库中增加了2条记录，执行 /usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed 看到有两个文档被加入索引（增量部分），之后我执行 /usr/local/sphinx/bin/indexer &#8211;rotate &#8211;merge test1 test1stemmed &#8211;merge-dst-range deleted 0 0 将增量索引并入主索引，这是可以查询到新插入的数据，这时我再继续插入一条数据，执行 /usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed 提示信息是有3个文档被加入索引，让我非常奇怪，因为上两条纪录已经并入主索引了，这次怎么还会索引呢？之后我执行 /usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1 更新主索引，之后再执行/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed提示没有索引加入，这样就正确了，如果按照测试的结果，增量索引和主索引更新执行的时间要计划好。 [...]]]></description>
			<content:encoded><![CDATA[<p>应用越来越多的需要全文搜索技术来支撑，在Java中可以使用Lucene，一个非常优秀的引擎，在Hibernate中也整合了Lucene来做检索，但在使用PHP的过程中迫切需要找一个优秀的全文搜索引擎（虽然也可以把PHP和Lucene结合起来使用，但有些另类，有些生产环境也不能同时支持），以前在网上看到一些<a href="http://www.sphinxsearch.com/" target="_blank">Sphinx</a>的文章，一直没有实践，昨天我就花了一天的时间，配置测试了一下Sphinx。</p>
<p>由于我的PHP没有编译Sphinx模块，所以我主要是配置Sphinx+Mysql，在Mysql上测试全文搜索的效果，Mysql、Sphinx、中文分词的编译安装过程不详述，下面两篇文章挺好，安装时可以参考</p>
<p><a href="http://www.cnblogs.com/hushixiu/articles/1295605.html" target="_blank">Mysql+sphinx+中文分词简介</a></p>
<p><a href="http://blog.s135.com/post/360/" target="_blank">基于Sphinx+MySQL的千万级数据全文检索（搜索引擎）架构设计</a></p>
<p>我的编译安装过程没有遇到什么麻烦，就是编译Mysql的时候比较长，而且要注意把Innodb的引擎编译进去，我的Mysql编译参数如下</p>
<p>./configure &#8211;with-plugins=sphinx,innobase,heap &#8211;prefix=/usr/local/mysql &#8211;enable-assembler &#8211;with-charset=utf8 &#8211;with-extra-charsets=all &#8211;enable-thread-safe-client &#8211;with-big-tables &#8211;with-readline &#8211;with-ssl &#8211;with-embedded-server &#8211;enable-local-infile</p>
<p>比较奇怪的是innodb是支持了，heap不支持，这个问题下次再研究。</p>
<p>通过编译Mysql，使Mysql支持了Sphinx存储引擎，试了一下Sphinx的例子，成功搜索到了数据，如果我们要对自己的数据做索引，就要研究一下Sphinx的配置文件了。</p>
<p>Sphinx的配置文件在其安装目录下的etc目录下，你可以参考其例子的sphinx.conf创建自己的配置文件，在sphinx里有主要要配置的有两大块，一部分是source（数据源），另一部分是index（索引），source里面定义了连接数据库的参数，取得源数据的SQL，也就是你要索引的数据的取得 SQL（Sphinx是支持不同数据源的，我这里只测试SQL），source可以有继承关系，继承的source可以用来做取得增量数据，index里面定义了使用哪个source，index存放的路径、字符集、辞典等等，index也可以继承，继承的index用来做增量索引。由此可见source 和index都是根据你的需要配置的，可以取得多个数据源的数据，可以建立多个索引。</p>
<p>增量索引的小困惑，我在数据库中增加了2条记录，执行</p>
<p>/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed</p>
<p>看到有两个文档被加入索引（增量部分），之后我执行</p>
<p>/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;merge test1 test1stemmed &#8211;merge-dst-range deleted 0 0</p>
<p>将增量索引并入主索引，这是可以查询到新插入的数据，这时我再继续插入一条数据，执行</p>
<p>/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed</p>
<p>提示信息是有3个文档被加入索引，让我非常奇怪，因为上两条纪录已经并入主索引了，这次怎么还会索引呢？之后我执行</p>
<p>/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1</p>
<p>更新主索引，之后再执行/usr/local/sphinx/bin/indexer &#8211;rotate &#8211;config /usr/local/sphinx/etc/sphinx.conf test1stemmed提示没有索引加入，这样就正确了，如果按照测试的结果，增量索引和主索引更新执行的时间要计划好。</p>
<p>关于中文分词&#8211;<a href="http://www.coreseek.com/opensource/mmseg/" target="_blank">LibMMSeg</a>：LibMMSeg 是Coreseek.com为 Sphinx 全文搜索引擎设计的中文分词软件包，其在GPL协议下发行的中文分词法，采用<a href="http://chtsai.org/" target="_blank">Chih-Hao Tsai</a>的MMSEG算法。</p>
<p>同时Coreseek.com提供了一份Sphinx的<a href="http://www.coreseek.com/uploads/pdf/sphinx_doc_zhcn_0.9.pdf" target="_blank">中文文档</a>，里面有比较详细的配置说明，是很好的参考资料，非常感谢开源人士做出的贡献。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/sphinx-mysql.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

