<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/sphinx_search/</link>
<title><![CDATA[基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[搜索引擎技术]]></category>
<pubDate>Fri, 05 Feb 2010 00:50:25 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.0 最后修改：2010.02.05 转载请注明原文链接：<a href="http://blog.zyan.cc/sphinx_search/" target="_blank">http://blog.zyan.cc/sphinx_search/</a>]<br/><br/>　　前言：<br/><br/>　　2008年7月，我写过一篇文章《<a href="http://blog.zyan.cc/post/360/" target="_blank">基于Sphinx+MySQL的千万级数据全文检索（搜索引擎）架构设计</a>》。有不少网友希望阅读全文，我将该文档整理了一下，分享出来。文档解压后大小为7.33M，共19页。<br/><br/>　　<strong>本站下载地址：</strong> <a href="http://blog.zyan.cc/book/sphinx/sphinx_mysql.zip" target="_blank">http://blog.zyan.cc/book/sphinx/sphinx_mysql.zip</a><br/><br/>　　<strong>新浪下载分流：</strong> <a href="http://ishare.iask.sina.com.cn/f/6728201.html" target="_blank">http://ishare.iask.sina.com.cn/f/6728201.html</a><br/><br/>　　上述文档架构存在的局限，我在2008年12月的文章《<a href="http://blog.zyan.cc/post/385/" target="_blank">亿级数据的高并发通用搜索引擎架构设计</a>》中已经指出：一是MySQL本身的并发能力有限，在200～300个并发连接下，查询和更新就比较慢了；二是由于MySQL表的主键与Sphinx索引的ID一一对应，从而无法跨多表建立整站查询，而且新增加类别还得修改配置文件，比较麻烦；三是因为和MySQL集成，无法发挥出Sphinx的优势。虽然如此，但对于一些写入量不大的搜索应用，已经足够了，或许对很多人会有帮助。<br/><br/><hr/><br/>　　正文：<br/><br/>　　在这之后，本人基于《<a href="http://blog.zyan.cc/post/385/" target="_blank">亿级数据的高并发通用搜索引擎架构设计</a>》开发的Sphinx分布式通用站内搜索引擎平台，已经在生产环境运行9个月以上，经过运营中的不断完善与改进，目前已形成了一套可扩展的分布式通用站内搜索引擎框架。CMS、视频、论坛等产品发生的增、删、改操作，文本内容实时写入自行开发的 <a href="http://blog.zyan.cc/httpsqs" target="_blank">HTTPSQS</a> 高性能简单消息队列服务，通过队列控制器更新索引和存储。提供支持XML、JSON的API查询接口，支持亿级数据的索引、分布式、中文分词、高亮显示、自动摘要、准实时（1分钟内）增量索引更新。<br/><br/>　　<a href="http://zyan.cc/attachment/201002/search_system.png" target="_blank"><img src="http://zyan.cc/attachment/201002/search_system.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　下面是Sphinx新的搜索架构中技术关键点实现方式的一些介绍，与大家分享、交流一下：<br/><br/>　　<strong>1、一元分词和中文分词的结合：</strong><br/><br/>　　①、一元分词位于索引更新模块。Sphinx索引引擎对于CJK（中日韩）语言（必须是UTF-8编码）支持一元切分，假设【反恐行动是国产主视角射击网络游戏】这段文字，Sphinx会将其切成【反 恐 行 动 是 国 产 主 视 角 射 击 网 络 游 戏】，然后对每个字建立反向索引。如果用这句话中包含的字组成一个不存在的词语，例如【恐动】，也会被搜索到，所以搜索时，需要加引号，例如搜索【"反恐行动"】，就能完全匹配连在一起的四个字，不连续的【"恐动"】就不会被搜索到。但是，这样还有一个问题，搜索【"反恐行动游戏"】或【"国产网络游戏"】就会搜索不到。对于这个问题，采用位于搜索查询模块的中文分词来处理。<br/><br/>　　sphinx.conf配置文件中关于UTF-8中文一元分词的配置如下：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">...省略...<br/>index t_source_main<br/>&#123;<br/>&n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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= utf-8<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min_prefix_len&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html_strip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;charset_table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngram_len&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngram_chars&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = U+3000..U+2FA1F<br/>&#125;<br/>...省略...</div><br/><br/>　　②、中文分词位于搜索查询模块。搜索“反恐行动游戏”、“国产网络游戏”，先调用独立的中文分词系统，分别切分为“反恐行动 游戏”、“国产 网络游戏”，这时候，再给以空格分隔的词语加上引号，去Sphinx搜索【"反恐行动" "游戏"】或【"国产" "网络游戏"】，就能搜索到这条记录了。中文分词词库发生增、删、改，无需重建整个Sphinx搜索索引。<br/><br/><hr/><br/>　　<strong>2、使用自行开发的HTTPSQS（<a href="http://code.google.com/p/httpsqs" target="_blank">http://code.google.com/p/httpsqs</a>）开源简单队列服务程序，来缓冲高并发数据写入</strong><br/><br/>　　新闻、论坛帖子、客服公告、SNS社区等发生的增、删、改操作，文本内容通过更新接口实时写入HTTPSQS队列，再通过队列控制器更新到Sphinx搜索引擎索引中。<br/><br/><hr/><br/>　　<strong>3、Sphinx不能严格按照字段排序的小问题</strong><br/><br/>　　如果不想使用权重，只希望严格按照时间、主键等排序，而匹配模式（Matching modes）又为非SPH_MATCH_BOOLEAN时（比较常用的是SPH_MATCH_ALL、SPH_MATCH_EXTENDED），Sphinx搜索结果在某一页中的排序会不太准确。例如：按照UNIX时间戳倒序排序，0,20为第一页，20,40为第二页，第一页的最小时间戳一定会大于第二页的最大时间戳，但是，第一页中的0,20条记录却不会严格按照时间戳排序，第二页亦是如此。因此，如果需要精确排序，用户翻到搜索结果的某一页，就需要对Sphinx在某一搜索结果页中的记录另行再排序，在我的这套搜索架构中，这一再排序操作由search.php查询接口使用array_multisort()函数处理。一般情况下，一页只会显示5～30条记录，因此，只对几十条记录采用PHP再排序，速度也是非常快的。<br/><br/><hr/><br/>　　<strong>4、队列控制器中“时间控制”与“数量控制”相结合，实现搜索索引的1分钟内准实时更新：</strong><br/><br/>　　①、Sphinx 0.9.9生产环境的建索引速度大约在5.5 Mbytes/秒、6400文档/秒。队列控制器可以设置10秒钟更新一次增量索引，只要Sphinx增量索引数据源的文档数在38万以内，就能保证增量索引在1～60秒内得到更新，这是从“时间”上进行控制。<br/><br/>　　②、为了避免增量索引数据源的文档数增长到38万，队列控制器在增量索引数据源的文档数超过1万时，还将激活增量索引合并入主索引的操作，合并完成的文档将从增量索引数据源中删除，这是从“数量”上进行控制。<br/><br/>............<br/><br/>Tags - <a href="http://zyan.cc/tags/sphinx/" rel="tag">sphinx</a> , <a href="http://zyan.cc/tags/search/" rel="tag">search</a> , <a href="http://zyan.cc/tags/api/" rel="tag">api</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4937</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>燕南天 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 01:30:27 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4937</guid> 
<description>
<![CDATA[ 
	真的不错呦~~~~
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4939</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>marker &lt;marker_xu@fim.com.cn&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 02:02:08 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4939</guid> 
<description>
<![CDATA[ 
	张宴大师，，facebook出了个HipHop，，据说对性能提升很大，，你写篇文章分析一下吧
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4940</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>Jason Yu &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 02:14:57 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4940</guid> 
<description>
<![CDATA[ 
	非常感谢你技术上的分享。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4941</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>frankboy &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 02:29:33 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4941</guid> 
<description>
<![CDATA[ 
	您老什么时候把那个安装linux的PPt更新到Centos5.4啊。期待中
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4943</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>glovebx &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 03:49:39 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4943</guid> 
<description>
<![CDATA[ 
	每次阅读你的文章受益匪浅，感谢分享。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4945</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>怪物宝 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 05:14:23 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4945</guid> 
<description>
<![CDATA[ 
	我也想知道大侠对HipHop有什么意见
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4946</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>dikiking &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 05:24:43 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4946</guid> 
<description>
<![CDATA[ 
	强烈支持啊。。。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4947</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>niniwzw &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 05:30:22 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4947</guid> 
<description>
<![CDATA[ 
	HipHop 估计对一般的小用户没有什么用，一般的网站瓶颈在数据库 而不是 php。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4948</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>niniwzw &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 05:42:23 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4948</guid> 
<description>
<![CDATA[ 
	非常佩服你，开源的东西能玩的这样溜。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4949</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>enjoy &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 07:05:48 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4949</guid> 
<description>
<![CDATA[ 
	感谢分享《Sphinx搜索引擎架构与使用文档(和MySQL结合)》，但是有个疑问，增量索引后不需要合并索引吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4951</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>kylingood &lt;kylingood@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 07:57:59 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4951</guid> 
<description>
<![CDATA[ 
	终于等来了。。。。支持兄弟了。。。。哈哈。。。。谢谢开源精神~~~~
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4952</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>solomon &lt;sucrede@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 08:01:29 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4952</guid> 
<description>
<![CDATA[ 
	非常感谢 
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4955</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>luoke &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 05 Feb 2010 08:54:31 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4955</guid> 
<description>
<![CDATA[ 
	我终于等到这一刻了，绝对的支持。
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4961</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>chris &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 06 Feb 2010 02:23:57 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4961</guid> 
<description>
<![CDATA[ 
	和Linkedin的Zoie+Bobo-Browser比起来怎么样？
]]>
</description>
</item><item>
<link>http://zyan.cc/sphinx_search/#blogcomment4964</link>
<title><![CDATA[[评论] 基于Sphinx构建准实时更新的分布式通用搜索引擎平台[原创]]]></title> 
<author>心若止水 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 07 Feb 2010 04:24:05 +0000</pubDate> 
<guid>http://zyan.cc/sphinx_search/#blogcomment4964</guid> 
<description>
<![CDATA[ 
	受益良多 学无止境
]]>
</description>
</item>
</channel>
</rss>