<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[coreseek在windows环境下安装和使用]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Sat, 22 Oct 2016 12:58:27 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	　　先写个结论，sphinx本身是可以支持中文搜索的，只是不支持中文分词，需要安装中文分词插件，coreseek就是一个打包了mmseg中文分词插件和sphinx源码的安装包。<br/>　　<br/>　　<strong>概念讲解</strong><br/>　　<br/>　　Sphinx全文搜索引擎<br/>　　<br/>　　一般用作大数据量的搜索支持<br/>　　<br/>　　Sphinx特性<br/>　　<br/>　　1:Sphinx支持高速建立索引（可达10MB/秒，而Lucene建立索引的速度是1.8MB/秒）<br/>　　<br/>　　2:高性能的搜索（在2--4GB的文本数据上，平均每次检索响应时间小于0.1秒)<br/>　　<br/>　　3:高扩展性（实测最高可对100GB的文本建立索引，单一索引可包含1亿条记录）<br/>　　<br/>　　4:提供了优秀的相关度算法，基于短语相似度和统计（BM25）的复合Ranking方法<br/>　　<br/>　　5:支持分布式搜索<br/>　　<br/>　　6:支持短语搜索<br/>　　<br/>　　7:可作为MySQL的存储引擎提供搜索服务<br/>　　<br/>　　8:支持布尔、短语、词语相似度等多种检索模式<br/>　　<br/>　　9:文档支持多个全文检索字段<br/>　　<br/>　　而我们在这里讲的是Coreseek。<br/>　　<br/>　　Coreseek是基于Sphinx开发的一款软件，对Sphinx做了一些改动，在中文方面支持得比Sphinx好<br/>　　<br/>　　如果是做中文的全文搜索引擎，现在用Coreseek.<br/>　　<br/>　　<strong>1、准备工作 （手工）</strong><br/>　　<br/>　　数据库创建，导入数据<br/>　　<br/>　　下载coreseek文件（我的是coreseek-4.1-win32），解压到E:&#92;coreseek（目录随便解压），解压目录如下：<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.dzhope.com/attachment.php?fid=82" target="_blank"><img src="http://www.dzhope.com/attachment.php?fid=82" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>　　<br/>　　<strong>2、建立sphinx配置文件sphinx.conf (手工)</strong><br/>　　<br/>　　在etc目录下建立sphinx.conf（名字随便）文件或者将csft_mysql.conf改名为sphinx.conf<br/>　　<br/>　　配置参数(后面会提到)<br/>　　<br/>　　<strong>3、命令生成索引(手工，执行命令)</strong><br/>　　<br/>　　开始”——>“运行”——>输入cmd，打开命令行窗口——>执行 "e: 回车"——>执行 "cd coreseek"，进入到 coreseek目录下<br/>　　<br/>　　执行 "set PATH=%CD%&#92;bin;%PATH%"。设置path，目的是为了能够调用bin目录下的 cat.exe、iconv.exe 等<br/>　　<br/>　　bin&#92;indexer -c etc&#92;sphinx.conf&nbsp;&nbsp;--all&nbsp;&nbsp;在 coreseek&#92;var&#92;data 下发现，生成多个后缀不同文件。<br/>　　<br/>　　<strong>4、数据测试（命令行下不需要开启 searchd 服务）</strong><br/>　　<br/>　　测试搜索中文。<br/>　　<br/>　　命令 为“ echo 搜索的词 &#124; iconv -f gbk -t utf-8 &#124; search -c etc&#92;csft_mysql.conf --stdin &#124; iconv -f utf-8 -t gbk ”<br/>　　<br/>　　搜索英文，出现乱码是正常的。命令为” bin&#92;search -c etc&#92;csft_mysql.conf 搜索词“<br/>　　<br/>　　<strong>5、将 searchd 安装成为一个服务。</strong><br/>　　<br/>　　执行 "bin&#92;searchd --install --config e:/coreseek/etc/sphinx.conf"，安装成功后命令行窗口会提示" services searchd installed successfully"<br/>　　<br/>　　注意两点<br/>　　<br/>　　（1）、win7下命令行窗口需要以管理员身份运行，否则会出现”fatal openscmanager“错误而无法安装<br/>　　<br/>　　（2）、如果不把 searchd 安装成为服务，那每次使用 coreseek 全文搜索，都得在命令行窗口打开 searchd 服务且不可关闭或停止（命令行窗口不需要开启，使用api接口时需要）<br/>　　<br/>　　补充一点，无法正常安装，或安装后启动该服务时出现1067错误，很有可能是路径问题：一是需要注意数据源配置文件里全部使用绝对路径；二是上面的 install命令，也需要使用绝对路径，而且路径用 '/' ，不能是 '&#92;'。<br/>　　<br/>　　以上是在服务器端安装配置Coreseek，下面就需要在客户端使用了<br/>　　<br/>　　<strong>6、php使用coreseek</strong><br/>　　<br/>　　在web根目录下建立一个search目录（当然不在根目录也行，同样目录名也可以随取），复制E:&#92;coreseek&#92;api&#92; sphinxapi.php文件到search目录（sphinxapi.php这个是sphinx官方提供的api），开始php程序的编写。<br/>　　<br/>　　<div class="code"><br/>　　<br/>　　&lt;?php<br/>　　<br/>　　include &#039;sphinxapi.php&#039;;&nbsp;&nbsp;// 加载Sphinx API<br/>　　<br/>　　$sc = new SphinxClient(); // 实例化Api<br/>　　<br/>　　$sc-&gt;setServer(&#039;localhost&#039;, 9312); // 设置服务端，第一个参数sphinx服务器地址，第二个sphinx监听端口<br/>　　<br/>　　$res = $sc-&gt;query(&#039;sphinx&#039;, &#039;mysql&#039;);<br/>　　<br/>　　// 执行查询，第一个参数查询的关键字，<br/>　　<br/>　　// 第二个查询的索引名称，mysql索引名称（这个也是在配置文件sphinx.conf中定义的），<br/>　　<br/>　　//多个索引名称以,分开，也可以用*表示所有索引。<br/>　　<br/>　　print_r($res);<br/>　　<br/>　　?&gt;<br/>　　<br/>　　</div><br/>　　<br/>　　Matches中就是查询的结果了，但是仿佛不是我们想要的数据，比如titile，content字段的内容就没有查询出来，根据官方的说明是Sphinx并没有连接到MySQL去取数据，只是根据它自己的索引内容进行计算，因此如果想用Sphinx提供的API去取得我们想要的数据，还必须以查询的结果为依据，再次查询MySQL从而得到我们想要的数据。<br/>　　<br/>　　下一页的内容主要为coreseek常用命令以及sphinx.conf源配置和索引配置参数说明<br/>　　<br/>　　<strong>常用命令</strong><br/>　　<br/>　　<strong>1、创建搜索服务</strong><br/>　　<br/>　　bin&#92;searchd --install --config e:/coreseek/etc/sphinx.conf servicename sphinx（--install仅在windows下有效）<br/>　　<br/>　　此处执行了两个命令:<br/>　　<br/>　　1)&nbsp;&nbsp;&nbsp;&nbsp; install命令，安装searchd作为服务<br/>　　<br/>　　2)&nbsp;&nbsp;&nbsp;&nbsp; config命令，配置sphinx.conf文件<br/>　　<br/>　　<strong>2、启动搜索服务</strong><br/>　　<br/>　　bin/searchd -c etc/sphinx.conf<br/>　　<br/>　　<strong>3、停止搜索服务</strong><br/>　　<br/>　　bin/searchd -c etc/sphinx.conf --stop<br/>　　<br/>　　<strong>4、强制关闭searchd服务</strong><br/>　　<br/>　　killall -9 searchd<br/>　　<br/>　　<strong>5、建立索引</strong><br/>　　<br/>　　bin/indexer -c etc/sphinx.conf --all<br/>　　<br/>　　<strong>6、更新索引某一索引（更新完成后需要重启searchd服务）</strong><br/>　　<br/>　　bin/indexer -c etc/sphinx.conf xxxx&nbsp;&nbsp; (xxxx为需要更新的索引名)<br/>　　<br/>　　在searchd服务运行的时候，更新索引(更新完成后不需要重启searchd服务)<br/>　　<br/>　　bin/indexer -c etc/sphinx.conf&nbsp;&nbsp;--rotate xxxx&nbsp;&nbsp; (xxxx为需要更新的索引名)<br/>　　<br/>　　<strong>7.关键字检索</strong><br/>　　<br/>　　bin/search -c etc/sphinx.conf 关键词<br/>　　<br/>　　sphinx配置文件讲解<br/>　　<br/>　　source：数据源，数据是从什么地方来的。<br/>　　<br/>　　index：索引，当有数据源之后，从数据源处构建索引。索引实际上就是相当于一个字典检索。有了整本字典内容以后，才会有字典检索。<br/>　　<br/>　　searchd：提供搜索查询服务。它一般是以deamon的形式运行在后台的。<br/>　　<br/>　　indexer：构建索引的服务。当要重新构建索引的时候，就是调用indexer这个命令。<br/>　　<br/>　　attr：属性，属性是存在索引中的，它不进行全文索引，但是可以用于过滤和排序。<br/>　　<br/>　　<strong>配置文件</strong><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="attachment.php?fid=83">点击这里下载文件</a><br/>Tags - <a href="http://www.dzhope.com/tags/sphinx/" rel="tag">sphinx</a> , <a href="http://www.dzhope.com/tags/%25E5%2585%25A8%25E6%2596%2587%25E6%25A3%2580%25E7%25B4%25A2/" rel="tag">全文检索</a> , <a href="http://www.dzhope.com/tags/coreseek/" rel="tag">coreseek</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] coreseek在windows环境下安装和使用]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>