在ubuntu 下安装sphinx

在ubuntu 下安装sphinx
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-sphinx-on-ubuntu-14-04

安装包下的doc不准确。这篇文章写的很好。

为保持索引及时更新,在crontab中加入,每小时执行一次索引更新
@hourly /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all

执行
search this is my test document number

报错:
The program 'search' is currently not installed. You can install it by typing:
sudo apt-get install sphinxsearch

结论:http://sphinxsearch.com/forum/view.html?id=14124
Looks like search tool got removed in version 2.2.2:

> removed deprecated CLI search and sql_query_info

You are running:

> Sphinx 2.2.10-id64-release


search被删除掉了!


另外参考:
http://blog.51yip.com/mysql/1659.html

通过PHP调用sphinx有2种方式,
1 将sphinx 添加为php模块
2 调用sphinx api

1 参考 http://hongtoushizi.iteye.com/blog/1936938
执行
sudo pear install pecl/sphinx
安装后修改/etc/php5/apache2/php.ini
将extension=sphinx.so添加上去。然后重启apache2,安装成功后

在phpinfo中会见到
sphinx
sphinx support enabled
Version 1.3.3
Revision $Revision$


2 API 方式请下载
https://github.com/romainneutron/Sphinx-Search-API-PHP-Client

需要使用的时候,要加上require ( "sphinxapi.php" );

2种方式用法都一样

$host = "localhost";
        $port = 1238;
        $index = "geostemmed";
        $cl = new SphinxClient();
        $cl->SetServer ( $host, $port );
        $cl->SetSortMode ( SPH_SORT_EXTENDED, "@relevance DESC, @id DESC" );
        $cl->SetMatchMode ( $mode );
        $cl->SetLimits(0,25);
        $res = $cl->Query ( $q, $index );

猜你喜欢

转载自lhdst-163-com.iteye.com/blog/2327866