当前位置: 首页>>代码示例>>PHP>>正文


PHP SphinxClient::escapeString方法代码示例

本文整理汇总了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;
 }
开发者ID:headzoo,项目名称:sphinx-search-bundle,代码行数:60,代码来源:SphinxSearch.php

示例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;
 }
开发者ID:remilemonnier,项目名称:SphinxsearchBundle0.9,代码行数:66,代码来源:Sphinxsearch.php

示例3: escapeString

 public function escapeString($string)
 {
     return $this->sphinx->escapeString($string);
 }
开发者ID:maninhat,项目名称:search-sphinxsearchbundle,代码行数:4,代码来源:Sphinxsearch.php


注:本文中的SphinxClient::escapeString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。