sphinx 的安装及使用 windws centos coreseek
$cl = new SphinxClient ();
$cl->SetServer ( '127.0.0.1', 9312);
$cl->SetConnectTimeout ( 3 );
$cl->SetArrayResult ( true );
$cl->SetMatchMode ( SPH_MATCH_ANY);
$cl->SetLimits(20,10);//分页
$res = $cl->Query ( '已经被我们格式化了', "*" );
if(isset($res['matches'])){
?
??? $ids = '';
??? foreach($res['matches'] as $r){
??? ??? $ids .=$r['id'].',';
??? }
??? $ids = substr($ids,0,-1);
??? $idsarr = explode(',',$ids);
??? $conn = new mysqli('localhost','root','','demo');
??? $conn->set_charset('utf8');
??? $sql = "select id,title,contents from articles where id in ($ids)";
??? echo $sql;
??? $result = $conn->query($sql);
?
??
?? $words = array_keys($res['words']);
?? var_dump($words);
?? //将数据库查出来的数组放到新数组中,并使用数组的键名为IN 的ID,这样方便排序
?? $data = array();
??? while($i = $result->fetch_assoc()){
??? ??? echo $i['id'].replacestr($words,$i['title']).'<br/><br/>';
??? ??? echo replacestr($words,$i['contents']).'<br/>';*/
??? ??? $data[$i['id']] = $i;
??? }
??? foreach($idsarr as $i){
??? ??? echo '<br/>=================================<br/><br/><br/><br/>';
??? ??? echo $data[$i]['id'].replacestr($words, $data[$i]['title']).'<br/><br/>';
??? ??? echo replacestr($words, $data[$i]['contents']).'<br/>';
??? }
???
???
??? echo '<br/>';
??? echo '<br/>';
??? var_dump($res['matches']);
}else{
??? echo ' not matches<br/><br/>';
??? var_dump($res);
}
print_r($cl);
print_r($res);
function replacestr($arr,$str){
??? foreach($arr as $r){
??? ??? $str = str_replace($r,"<span style='color:red'>".$r."</span>",$str);
??? }
??? return $str;
}
?
这样就不需要进行索引合并(索引合并会带来较大的IO操作)
-----------------------------------2011-8-24---------------------------------------
?
参考:http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html#live-updates
?
============================
在 centos5.6 64位机器上用coreseek4.1 beta时出错
重装libliconv都不行
============================
/usr/local/sphinx/src/sphinx.cpp:15557: undefined reference to `libiconv_open'
libsphinx.a(sphinx.o)(.text+0x53a01):/usr/local/sphinx/src/sphinx.cpp:15575: undefined
reference to `libiconv'
libsphinx.a(sphinx.o)(.text+0x53a28):/usr/local/sphinx/src/sphinx.cpp:15581: undefined
reference to `libiconv_close'
?
官方解决方法
## 如果出现undefined reference to `libiconv'的类似错误,可以按照如下方法处理:
##方法一:(Linux使用)
## 直接执行:export LIBS="-liconv"
##然后再次configure后,进行编译安装make && make install
?
?
民间解决方法
?
安装sphinx时又报错