PHP code example of lampol / sphinx
1. Go to this page and download the library: Download lampol/sphinx library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lampol / sphinx example snippets
use lampol\SphinxClient;
$sc = new SphinxClient ();
$words = $_POST['keywords'];
$host = "localhost";
$port = 9312;
$index = "user";
//设置 sphinx服务以及端口 默认是localhost 端口9312
$sc->SetServer ( $host, $port );
//设置连接的超时时间
$sc->SetConnectTimeout ( 1 );
//返回数组的数据格式
$sc->SetArrayResult ( true );
//设置返回的条数 分页
//$offset=30;
//$limit=10;
$sc->SetLimits ( $offset, $limit);
//开始查询
$res = $sc->Query ( $words, $index );
echo '<pre>';
var_dump($res);
echo '</pre>';