本文整理汇总了PHP中SphinxClient::SetConnectTimeout方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetConnectTimeout方法的具体用法?PHP SphinxClient::SetConnectTimeout怎么用?PHP SphinxClient::SetConnectTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetConnectTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SphinxClient
/**
* Constructor.
*
* @param string $host The server's host name/IP.
* @param string $port The port that the server is listening on.
* @param array $indexes The list of indexes that can be used.
*/
function __construct()
{
//sphinx
$sphinxconf = Yaf_Registry::get("config")->get('sphinx')->toArray();
$this->host = $sphinxconf['host'];
$this->port = $sphinxconf['port'];
$this->indexes = $sphinxconf['indexes'];
$this->sphinx = new SphinxClient();
$this->sphinx->SetServer($this->host, $this->port);
//sphinx连接超时时间,单位为秒
$this->sphinx->SetConnectTimeout(5);
//sphinx搜索结果集返回方式:TRUE为普通数组返回,FALSE为PHP hash格式返回
$this->sphinx->SetArrayResult(false);
//sphinx最大搜索时间,单位为毫秒
$this->sphinx->SetMaxQueryTime(5000);
//匹配模式
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
//设置权重评分模式,详见sphinx文档第6.3.2节:SetRankingMode
$this->sphinx->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
//设置排序模式排序模式
$this->sphinx->SetSortMode(SPH_SORT_EXTENDED, '@weight DESC,@id DESC');
//中文分词配置
$httpcwsconf = Yaf_Registry::get("config")->get('httpcws')->toArray();
//中文分词HTTPCWS服务器接口地址
$this->httpcws_url = 'http://' . $httpcwsconf['host'] . ':' . $httpcwsconf['port'] . '/?w=';
}
示例2: initialize
/**
* Initialize the Sphinx search engine
* @return void
*/
public function initialize()
{
$this->_connectionOptions = array('host_name' => $this->modx->getOption('discuss.sphinx.host_name', null, 'localhost'), 'port' => $this->modx->getOption('discuss.sphinx.port', null, 9312), 'connection_timeout' => $this->modx->getOption('discuss.sphinx.connection_timeout', null, 30), 'searchd_retries' => $this->modx->getOption('discuss.sphinx.searchd_retries', null, 3), 'searchd_retry_delay' => $this->modx->getOption('discuss.sphinx.searchd_retry_delay', null, 10000));
$this->_indices = $this->modx->getOption('discuss.sphinx.indexes', null, 'discuss_posts');
$this->client = new SphinxClient();
$this->client->SetServer($this->_connectionOptions['host_name'], $this->_connectionOptions['port']);
$this->client->SetConnectTimeout($this->_connectionOptions['connection_timeout']);
$this->client->SetMatchMode(SPH_MATCH_EXTENDED);
return true;
}
示例3: _initSphinx
/**
* 初始化搜索引擎
*/
private function _initSphinx()
{
$this->_loadCore('Help_SphinxClient');
$this->_sphinx = new SphinxClient();
$this->_sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
$this->_sphinx->SetConnectTimeout(5);
//连接时间
$this->_sphinx->SetArrayResult(true);
$this->_sphinx->SetMaxQueryTime(10);
//设置最大超时时间
$this->_sphinx->SetMatchMode(SPH_MATCH_ANY);
//匹配模式
}
示例4: _initSphinx
/**
* 初始化搜索引擎
*/
private function _initSphinx()
{
import('@.Util.SphinxClient');
$this->_sphinx = new SphinxClient();
$this->_sphinx->SetServer(C('SPHINX_HOST'), C('SPHINX_PORT'));
$this->_sphinx->SetConnectTimeout(5);
//连接时间
$this->_sphinx->SetArrayResult(true);
//设置数组返回
$this->_sphinx->SetMaxQueryTime(10);
//设置最大超时时间
$this->_sphinx->SetMatchMode(SPH_MATCH_ANY);
//匹配模式
}
示例5: searchTasks
/**
*
* @param string $query
* @return array of integers - taskIds
*/
public static function searchTasks($query)
{
$fieldWeights = array('description' => 10, 'note' => 6);
$indexName = 'plancake_tasks';
$client = new SphinxClient();
// $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port'));
$client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId()));
$client->SetConnectTimeout(1);
$client->SetMatchMode(SPH_MATCH_ANY);
$client->SetSortMode(SPH_SORT_RELEVANCE);
$client->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$client->SetArrayResult(true);
$client->SetFieldWeights($fieldWeights);
$client->setLimits(0, 100);
$results = $client->query($client->EscapeString($query), $indexName);
if ($results === false) {
$error = "Sphinx Error - " . $client->GetLastError();
sfErrorNotifier::alert($error);
}
$ids = array();
if (isset($results['matches']) && count($results['matches'])) {
foreach ($results['matches'] as $match) {
$ids[] = $match['id'];
}
}
return PcTaskPeer::retrieveByPKs($ids);
}
示例6: SphinxClient
function hook_search($search)
{
$offset = 0;
$limit = 500;
$sphinxClient = new SphinxClient();
$sphinxpair = explode(":", SPHINX_SERVER, 2);
$sphinxClient->SetServer($sphinxpair[0], (int) $sphinxpair[1]);
$sphinxClient->SetConnectTimeout(1);
$sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, 'feed_title' => 20));
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$sphinxClient->SetLimits($offset, $limit, 1000);
$sphinxClient->SetArrayResult(false);
$sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
$result = $sphinxClient->Query($search, SPHINX_INDEX);
$ids = array();
if (is_array($result['matches'])) {
foreach (array_keys($result['matches']) as $int_id) {
$ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
array_push($ids, $ref_id);
}
}
$ids = join(",", $ids);
if ($ids) {
return array("ref_id IN ({$ids})", array());
} else {
return array("ref_id = -1", array());
}
}
示例7: __construct
public function __construct(array $config)
{
$this->_sphinx = new \SphinxClient();
if (isset($config['host'])) {
if (!isset($config['host'])) {
$config['port'] = 9312;
}
$this->_sphinx->SetServer($config['host'], $config['port']);
}
if (isset($config['retries'])) {
if (!isset($config['delay'])) {
$config['delay'] = 0;
}
$this->_sphinx->SetRetries($config['retries'], $config['delay']);
}
if (isset($config['timeout'])) {
$this->_sphinx->SetConnectTimeout($config['timeout']);
}
}
示例8: __construct
public function __construct(Application $app, $host, $port, $rt_host, $rt_port)
{
$this->app = $app;
$this->sphinx = new \SphinxClient();
$this->sphinx->SetServer($host, $port);
$this->sphinx->SetArrayResult(true);
$this->sphinx->SetConnectTimeout(1);
$this->suggestionClient = new \SphinxClient();
$this->suggestionClient->SetServer($host, $port);
$this->suggestionClient->SetArrayResult(true);
$this->suggestionClient->SetConnectTimeout(1);
try {
$this->rt_conn = @new \PDO(sprintf('mysql:host=%s;port=%s;', $rt_host, $rt_port));
$this->rt_conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
$this->rt_conn = null;
}
return $this;
}
示例9: _getSphinxClient
private function _getSphinxClient()
{
require_once SCRIPT_BASE . 'lib/sphinx-2.1.9/sphinxapi.php';
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer('127.0.0.1', 9312);
$sphinxClient->SetConnectTimeout(20);
$sphinxClient->SetArrayResult(true);
$sphinxClient->SetWeights(array(1000, 1));
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED);
return $sphinxClient;
}
示例10: getSphinxClient
/**
* @return SphinxClient
*/
public function getSphinxClient()
{
if (null === $this->_sphinxClient) {
if (!class_exists("SphinxClient")) {
$this->load->library('sphinx/sphinxapi');
}
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer($this->config->get('sphinx_search_server'), $this->config->get('sphinx_search_port'));
$sphinxClient->SetConnectTimeout(1);
//$sphinxClient->_mbenc = "UTF-8";
$sphinxClient->ResetFilters();
$this->_sphinxClient = $sphinxClient;
}
return $this->_sphinxClient;
}
示例11: getResultByTag
public function getResultByTag($keyword = "", $offset = 0, $limit = 0, $searchParams = array())
{
$sphinx = $this->config->item('sphinx');
$query = array();
$cl = new SphinxClient();
$cl->SetServer($sphinx['ip'], $sphinx['port']);
// 注意这里的主机
$cl->SetConnectTimeout($sphinx['timeout']);
$cl->SetArrayResult(true);
// $cl->SetIDRange(89,90);//过滤ID
if (isset($searchParams['provice_sid']) && $searchParams['provice_sid']) {
$cl->setFilter('provice_sid', array($searchParams['provice_sid']));
}
if (isset($searchParams['city_sid']) && $searchParams['city_sid']) {
$cl->setFilter('city_sid', array($searchParams['city_sid']));
}
if (isset($searchParams['piccode']) && $searchParams['piccode']) {
$cl->setFilter('piccode', array($searchParams['piccode']));
}
if (isset($searchParams['recent']) && $searchParams['recent']) {
$cl->SetFilterRange('createtime', time() - 86400 * 30, time());
//近期1个月
}
if (isset($searchParams['searchtype']) && $searchParams['searchtype']) {
//精确:模糊
$searchtype = SPH_MATCH_ALL;
} else {
$searchtype = SPH_MATCH_ANY;
}
$cl->SetLimits($offset, $limit);
$cl->SetMatchMode($searchtype);
// 使用多字段模式
$cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc,@id desc");
$index = "*";
$query = $cl->Query($keyword, $index);
$cl->close();
return $query;
}
示例12: setConnectionTimeout
public function setConnectionTimeout($timeout)
{
$this->sphinxClient->SetConnectTimeout((int) $timeout);
}
示例13: SphinxClient
<?php
require "sphinxapi.php";
$cl = new SphinxClient();
$cl->SetServer('127.0.0.1', 9312);
$cl->SetConnectTimeout(1);
$cl->SetArrayResult(true);
// $cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetRankingMode(SPH_RANK_WORDCOUNT);
// $cl->SetSortMode ( SPH_SORT_EXTENDED, '@weight DESC' );
// $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
// $cl->SetFieldWeights(array('title'=>10,'content'=>1));
$res = $cl->Query('sphinxse', "*");
print_r($res['matches']);
示例14: sphinx_search
function sphinx_search($query, $offset = 0, $limit = 30)
{
require_once 'lib/sphinxapi.php';
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer('localhost', 9312);
$sphinxClient->SetConnectTimeout(1);
$sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, 'feed_title' => 20));
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$sphinxClient->SetLimits($offset, $limit, 1000);
$sphinxClient->SetArrayResult(false);
$sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
$result = $sphinxClient->Query($query, SPHINX_INDEX);
$ids = array();
if (is_array($result['matches'])) {
foreach (array_keys($result['matches']) as $int_id) {
$ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
array_push($ids, $ref_id);
}
}
return $ids;
}
示例15: SphinxClient
<?php
require 'sphinxapi.php';
$cl = new SphinxClient();
$cl->SetServer('localhost');
$cl->SetConnectTimeout(5);
$cl->SetMatchMode(SPH_MATCH_ANY);
$cl->SetLimits(0, 25, 1000);
$cl->SetArrayResult(true);
$result = $cl->Query('Codeine');
if ($result === false) {
echo "Query failed: " . $cl->GetLastError() . ".\n";
} else {
if ($cl->GetLastWarning()) {
echo "WARNING: " . $cl->GetLastWarning();
}
print '<pre>';
// if(!empty($result["matches"])){
// print '<pre>';
// foreach ( $result["matches"] as $doc => $docinfo ) {
print_r($result["matches"]);
// }
// }
}