本文整理汇总了PHP中SphinxClient::IsConnectError方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::IsConnectError方法的具体用法?PHP SphinxClient::IsConnectError怎么用?PHP SphinxClient::IsConnectError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::IsConnectError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: openConnection
/**
* Open Sphinx persistent connection.
*
* @throws ESphinxException if client is already connected.
* @throws ESphinxException if client has connection error.
* @link http://sphinxsearch.com/docs/current.html#api-func-open
*/
public function openConnection()
{
if ($this->isConnected) {
throw new ESphinxException("Sphinx client is already opened");
}
$this->sphinxClient->Open();
if ($this->sphinxClient->IsConnectError()) {
throw new ESphinxException("Sphinx exception: " . $this->sphinxClient->GetLastError());
}
$this->isConnected = true;
}
示例2: query
/**
* {@inheritdoc}
*/
public function query($query, $offset, $perPage, SearchEngineOptions $options = null)
{
if (null === $options) {
$options = new SearchEngineOptions();
}
$this->applyOptions($options);
assert(is_int($offset));
assert($offset >= 0);
assert(is_int($perPage));
$query = $this->parseQuery($query);
$preg = preg_match('/\\s?(recordid|storyid)\\s?=\\s?([0-9]+)/i', $query, $matches, 0, 0);
if ($preg > 0) {
$this->sphinx->SetFilter('record_id', [$matches[2]]);
$query = '';
}
$this->sphinx->SetLimits($offset, $perPage);
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$index = $this->getQueryIndex($query, $options);
$res = $this->sphinx->Query($query, $index);
$results = new ArrayCollection();
if ($res === false) {
if ($this->sphinx->IsConnectError() === true) {
$error = $this->app->trans('Sphinx server is offline');
} else {
$error = $this->sphinx->GetLastError();
}
$warning = $this->sphinx->GetLastWarning();
$total = $available = $duration = 0;
$suggestions = new ArrayCollection();
$propositions = [];
} else {
$error = $res['error'];
$warning = $res['warning'];
$duration = $res['time'];
$total = $res['total_found'];
$available = $res['total'];
$resultOffset = $offset;
if (isset($res['matches'])) {
foreach ($res['matches'] as $record_id => $match) {
try {
$record = new \record_adapter($this->app, $match['attrs']['sbas_id'], $match['attrs']['record_id'], $resultOffset);
$results->add($record);
} catch (\Exception $e) {
}
$resultOffset++;
}
}
$suggestions = $this->getSuggestions($query, $options);
$propositions = '';
}
return new SearchEngineResult($results, $query, $duration, $offset, $available, $total, $error, $warning, $suggestions, $propositions, $index);
}
示例3: search
/**
* Search for the specified query string.
*
* @param string $query The query string that we are searching for.
* @param array $indexes The indexes to perform the search on.
*
* @return ResultCollection The results of the search.
*
* $indexes should have the format:
*
* $indexes = array(
* 'IndexLabel' => array(
* 'result_offset' => (int),
* 'result_limit' => (int)
* ),
* ...,
* );
*/
public function search($query, array $indexes)
{
// $query = $this->sphinx->escapeString($query);
$results = array();
foreach ($indexes as $label => $options) {
/**
* Ensure that the label corresponds to a defined index.
*/
if (!isset($this->indexes[$label])) {
continue;
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit']) && is_numeric($options['result_offset']) && is_numeric($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (!empty($this->indexes[$label]['field_weights'])) {
$this->sphinx->setFieldWeights($this->indexes[$label]['field_weights']);
}
/**
* Perform the query.
*/
$results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
if ($this->sphinx->IsConnectError()) {
throw new ConnectionException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
} elseif ($results[$label]['status'] !== SEARCHD_OK) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
}
/**
* FIXME: Throw an exception if $results is empty?
*/
return new ResultCollection($results, $this->mapping, $this->em);
}
示例4: isConnectError
public function isConnectError()
{
return $this->_sphinx->IsConnectError();
}
示例5: getError
/**
* Return last error
* @param bool $conn
* @return bool|string
*/
public function getError($conn = false)
{
return !$conn ? $this->client->GetLastError() : $this->client->IsConnectError();
}