本文整理汇总了PHP中SphinxClient::escapeString方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::escapeString方法的具体用法?PHP SphinxClient::escapeString怎么用?PHP SphinxClient::escapeString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::escapeString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.
* @param array $options The options for the query.
* @param bool $escapeQuery Should the query string be escaped?
*
* @return array The results of the search.
*/
public function search($query, array $indexes, array $options = array(), $escapeQuery = true)
{
if ($escapeQuery) {
$query = $this->sphinx->escapeString($query);
}
/**
* Build the list of indexes to be queried.
*/
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
/**
* If no valid indexes were specified, return an empty result set.
*
* FIXME: This should probably throw an exception.
*/
if (empty($indexNames)) {
return array();
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$start = round(microtime(true) * 1000);
$results = $this->sphinx->query($query, $indexNames);
if ($results['status'] === SEARCHD_ERROR) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
if ($results['status'] === SEARCHD_RETRY) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with retry "%s".', $label, $query, $this->sphinx->getLastError()));
}
$end = round(microtime(true) * 1000) - $start;
$event = new SearchEvent($query, $indexes, $end);
$this->dispatcher->dispatch("sphinx.event.search", $event);
return $results;
}
示例2: 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 array The results of the search.
*
* $indexes should look like:
*
* $indexes = array(
* 'IndexLabel' => array(
* 'result_offset' => (int), // optional unless result_limit is set
* 'result_limit' => (int), // optional unless result_offset is set
* 'field_weights' => array( // optional
* 'FieldName' => (int),
* ...,
* ),
* ),
* ...,
* );
*/
public function search($query, array $indexes, $escapeQuery = true)
{
if ($escapeQuery) {
$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'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
if ($results[$label]['status'] !== SEARCHD_OK) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
}
/**
* If only one index was searched, return that index's results directly.
*/
if (count($indexes) === 1 && count($results) === 1) {
$results = reset($results);
}
/**
* FIXME: Throw an exception if $results is empty?
*/
return $results;
}
示例3: escapeString
public function escapeString($string)
{
return $this->sphinx->escapeString($string);
}