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


PHP SphinxClient::getLastError方法代码示例

本文整理汇总了PHP中SphinxClient::getLastError方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::getLastError方法的具体用法?PHP SphinxClient::getLastError怎么用?PHP SphinxClient::getLastError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SphinxClient的用法示例。


在下文中一共展示了SphinxClient::getLastError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
 }
开发者ID:maninhat,项目名称:search-sphinxsearchbundle,代码行数:56,代码来源:Sphinxsearch.php

示例4: getRelaCateCommon

 /**
  * 关键词获取普通产品获取相关分类
  * @param array $splitKeywords
  * @return array
  */
 public function getRelaCateCommon($splitKeywords, $cateid = 0, $limit = 20)
 {
     $sphinxConfig = $this->di["config"]["prosearchd"];
     $sphinx = new \SphinxClient();
     $sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
     $sphinx->SetSelect("id, cate3");
     $sphinx->SetFilter("cate3", array(1270), true);
     if ($cateid) {
         $sphinx->SetFilter("cate3", array($cateid), false);
     }
     $sphinx->SetFilterRange("id", 1, 900000000, false);
     $sphinx->SetLimits(0, $limit, $limit);
     $sphinx->SetGroupBy('cate3', SPH_GROUPBY_ATTR, "@count desc");
     $batchResult = $sphinx->query($splitKeywords, "product_distri");
     $error = $sphinx->getLastError();
     if ($error) {
         return array();
     }
     $result = $this->fomatSphinxData($batchResult);
     if (empty($result) || !is_array($result)) {
         $result = array();
     }
     return $result;
 }
开发者ID:tianyunchong,项目名称:php,代码行数:29,代码来源:SearchProToolService.php

示例5: getLastError

 /**
  * @brief returns errors if any
  */
 public function getLastError()
 {
     return $this->client->getLastError();
 }
开发者ID:zwq,项目名称:unpei,代码行数:7,代码来源:DGSphinxSearch.php

示例6: sphinx


//.........这里部分代码省略.........
     //二级分类筛选
     if (!empty($this->data['cate2id']) && intval($this->data['cate2id']) > 0) {
         $sphinx->SetFilter('cate2', array(intval($this->data['cate2id'])), false);
     }
     //地区筛选
     if (!empty($this->data['areaid']) && intval($this->data['areaid']) > 0) {
         if ($this->data['areaid'] % 10000 == 0) {
             $start = intval($this->data['areaid'] / 10000) * 10000;
             $end = $start + 9999;
             $sphinx->SetFilterRange('areaid', $start, $end, false);
         } elseif ($this->data['areaid'] % 100 == 0) {
             $start = intval($this->data['areaid'] / 100) * 100;
             $end = $start + 99;
             $sphinx->SetFilterRange('areaid', $start, $end, false);
         } else {
             $sphinx->SetFilter('areaid', array(intval($this->data['areaid'])));
         }
     }
     //成立时间筛选
     if (isset($this->data['foundstart']) && $this->data['foundstart'] > 0) {
         $start = intval($this->data['foundstart']);
         $end = isset($this->data['foundend']) && $this->data['foundend'] > $this->data['foundstart'] ? intval($this->data['foundend']) : time();
         $sphinx->SetFilterRange('startdate', $start, $end, false);
     }
     //成立时间筛选
     if (isset($this->data['busstart']) && $this->data['busstart'] > 0) {
         $start = intval($this->data['busstart']);
         $end = isset($this->data['busend']) && $this->data['busend'] > $this->data['busstart'] ? intval($this->data['busend']) : time();
         $sphinx->SetFilterRange('businessstart', $start, $end, false);
     }
     //注册资本
     if (isset($this->data['regcapstart']) && $this->data['regcapstart'] > 0) {
         $start = intval($this->data['regcapstart']);
         $end = isset($this->data['regcapend']) && $this->data['regcapend'] > $this->data['regcapstart'] ? intval($this->data['regcapend']) : 100000000;
         $sphinx->SetFilterRange('regcapital', $start, $end, false);
     }
     //企业状态
     if (isset($this->data['state']) && $this->data['state'] > 0) {
         if ($this->data['state'] == 10) {
             //有效企业
             $sphinx->SetFilterRange('intstate', 0, 10, false);
         } elseif ($this->data['state'] == 20) {
             //无效企业
             $sphinx->SetFilterRange('intstate', 11, 20, false);
         } else {
             $sphinx->SetFilter('intstate', array(intval($this->data['state'])), false);
         }
     }
     $offset = isset($this->data['offset']) ? intval($this->data['offset']) : 0;
     $limit = isset($this->data['limit']) ? intval($this->data['limit']) : 200;
     $max = isset($this->data['max']) ? intval($this->data['max']) : 200;
     $sphinx->SetLimits($offset, $limit, $max);
     //企业名称和企业法人搜索  企业注册号搜索
     if (!empty($this->data['wd'])) {
         //处理搜索词
         $keyArr = explode(' ', $this->data['split']);
         $keyArr = array_filter($keyArr);
         $keyStr = '';
         if (is_array($keyArr) && !empty($keyArr)) {
             foreach ($keyArr as $value) {
                 $keyStr .= '"' . $value . '" ';
             }
         }
         if (is_numeric($this->data['wd']) && mb_strlen($this->data['wd'], 'UTF-8') == 15) {
             //注册号全匹配搜索
             $sphinx->AddQuery('@regno ' . $this->data['wd'], $indexTable);
         } elseif ($t == 'legal') {
             //企业名称和法人搜索
             $sphinx->AddQuery('@legal ' . $this->data['wd'], $indexTable);
         } else {
             //企业名称和法人搜索
             $sphinx->AddQuery('@(comname,legal) ' . $keyStr, $indexTable);
         }
     } else {
         $sphinx->AddQuery('', $indexTable);
     }
     $batchResult = $sphinx->RunQueries();
     $error = $sphinx->getLastError();
     if ($error) {
         $result['data'] = array();
         $result['total_found'] = 0;
         $result['time'] = 0;
         return $result;
     }
     $result = array();
     if (is_array($batchResult) && count($batchResult) > 0) {
         $result['data'] = $batchResult[0];
         $result['total_found'] = $result['data']['total_found'];
         $result['time'] = $result['data']['time'];
     }
     $result['split'] = $this->data['split'];
     $cidArr = array();
     if (isset($result['data']['matches'])) {
         foreach ($result['data']['matches'] as $k => $v) {
             $cidArr[] = $v['attrs']['id'];
         }
     }
     $result['data'] = $cidArr;
     return $this->outputData($result);
 }
开发者ID:tianyunchong,项目名称:php,代码行数:101,代码来源:SearchCombusService.php

示例7: search_posts

 /**
  * Runs a search against sphinx
  *
  * @param array $args
  * @return array Sphinx result set
  */
 public function search_posts($args)
 {
     $options = $this->get_options();
     $defaults = array('search_using' => 'any', 'sort' => 'match', 'paged' => 1, 'posts_per_page' => 0, 'showposts' => 0);
     $args = wp_parse_args($args, $defaults);
     $sphinx = new SphinxClient();
     $sphinx->setServer($options['server'], $options['port']);
     $search = $args['s'];
     switch ($args['search_using']) {
         case 'all':
             $sphinx->setMatchMode(SPH_MATCH_ALL);
             break;
         case 'exact':
             $sphinx->setMatchMode(SPH_MATCH_PHRASE);
             break;
         default:
             $sphinx->setMatchMode(SPH_MATCH_ANY);
     }
     switch ($args['sort']) {
         case 'date':
             $sphinx->setSortMode(SPH_SORT_ATTR_DESC, 'date_added');
             break;
         case 'title':
             $sphinx->setSortMode(SPH_SORT_ATTR_ASC, 'title');
             break;
         default:
             $sphinx->setSortMode(SPH_SORT_RELEVANCE);
     }
     $page = isset($args['paged']) && intval($args['paged']) > 0 ? intval($args['paged']) : 1;
     $per_page = max(array($args['posts_per_page'], $args['showposts']));
     if ($per_page < 1) {
         $per_page = get_option('posts_per_page');
     }
     $sphinx->setLimits(($page - 1) * $per_page, $per_page);
     $sphinx->setMaxQueryTime(intval($options['timeout']));
     $result = $sphinx->query($search, $options['index']);
     $this->last_error = $sphinx->getLastError();
     $this->last_warning = $sphinx->getLastWarning();
     return $result;
 }
开发者ID:voceconnect,项目名称:wp-sphinx-search,代码行数:46,代码来源:wp-sphinx-search.php

示例8: fromSpecialSphinx


//.........这里部分代码省略.........
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'integral DESC');
                 break;
             default:
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'id DESC');
                 break;
         }
     } else {
         $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'id DESC');
     }
     if (isset($this->data['pid']) && $this->data['pid'] > 0) {
         $sphinx->SetLimits(0, 1, 1);
     } else {
         $sphinx->SetLimits(0, 200, 200);
     }
     $sphinx->AddQuery($this->data['split'], $indexTable);
     $sphinx->ResetGroupBy();
     $sphinx->SetGroupBy('feature', SPH_GROUPBY_ATTR, "@count desc");
     $sphinx->SetLimits(0, 20, 20);
     $sphinx->AddQuery($this->data['split'], $indexTable);
     $sphinx->ResetGroupBy();
     if (isset($this->data["pid"]) && $this->data["pid"] > 0) {
         $sphinx->SetLimits(0, 1, 1);
     } else {
         $sphinx->SetLimits(0, 20, 20);
     }
     $sphinx->SetGroupBy('brand', SPH_GROUPBY_ATTR, "@count desc");
     $sphinx->AddQuery($this->data['split'], $indexTable);
     if (!empty($this->data['province'])) {
         //市
         $sphinx->ResetGroupBy();
         $sphinx->SetLimits(0, 20, 20);
         $sphinx->SetGroupBy('city', SPH_GROUPBY_ATTR, "@count desc");
         $sphinx->AddQuery($this->data['split'], $indexTable);
     } else {
         //省
         $sphinx->ResetGroupBy();
         $sphinx->SetLimits(0, 20, 20);
         $sphinx->SetGroupBy('province', SPH_GROUPBY_ATTR, "@count desc");
         $sphinx->AddQuery($this->data['split'], $indexTable);
     }
     $batchResult = $sphinx->RunQueries();
     $error = $sphinx->getLastError();
     if ($error) {
         $result['data'] = array();
         $result['property'] = '[]';
         $result['brand'] = '[]';
         $result['city'] = '[]';
         $result['province'] = '[]';
         $result['total_found'] = 0;
         $result['time'] = 0;
         $result['split'] = $this->data['split'];
         return $result['data'];
     }
     $result = array();
     if (is_array($batchResult) && count($batchResult) > 0) {
         $result['data'] = $batchResult[0];
         $result['property'] = isset($batchResult[1]) ? $batchResult[1] : array();
         $result['brand'] = isset($batchResult[2]) ? $batchResult[2] : array();
         if (!empty($this->data['province'])) {
             $result['city'] = isset($batchResult[3]) ? $batchResult[3] : array();
         } else {
             $result['province'] = isset($batchResult[3]) ? $batchResult[3] : array();
         }
     }
     $resData = array();
     if (isset($result['data']['matches'])) {
         foreach ($result['data']['matches'] as $k => $v) {
             $resData[] = array($k, $v['attrs']['cid']);
         }
     }
     $result['total_found'] = $result['data']['total_found'];
     $result['time'] = $result['data']['time'];
     $result['split'] = $this->data['split'];
     $result['data'] = $resData;
     if (!empty($result['province'])) {
         $province = $this->fomatSphinxData($result['province']);
         $result['province'] = json_encode($province);
     } else {
         $result['province'] = '[]';
     }
     if (!empty($result['city'])) {
         $city = $this->fomatSphinxData($result['city']);
         $result['city'] = json_encode($city);
     } else {
         $result['city'] = '[]';
     }
     if (!empty($result['brand'])) {
         $brand = $this->fomatSphinxData($result['brand']);
         $result['brand'] = json_encode($brand);
     } else {
         $result['brand'] = '[]';
     }
     if (!empty($result['property'])) {
         $property = $this->fomatSphinxData($result['property']);
         $result['property'] = json_encode($property);
     } else {
         $result['property'] = '[]';
     }
     return $result;
 }
开发者ID:tianyunchong,项目名称:php,代码行数:101,代码来源:SearchProService.php

示例9: sphinxList


//.........这里部分代码省略.........
    /***************************************** 过滤结束 ******************************************/
    /***************************************** 排序 *********************************************/
    $sort = isset($filterArr['orders']['sort']) ? $filterArr['orders']['sort'] : '';
    if ($sort && $sort == 1) {
        //销量倒叙排列
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'tradenum DESC');
    } elseif ($sort && $sort == 2) {
        //热度倒叙排列
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'visitnum DESC');
    } elseif ($sort && $sort == 3) {
        //价格正序排列
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'price ASC');
    } elseif ($sort && $sort == 4) {
        //价格倒序排列
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'price DESC');
    } elseif ($sort && $sort == 5) {
        //返积分正序排列
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'integral DESC');
    } else {
        //默认综合排序
        $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'gcpdweight DESC');
    }
    /*************************************** 排序结束 ********************************************/
    /* limit限制 */
    $sphinx->SetLimits(0, $perpage * 10, $perpage * 10);
    $sphinx->AddQuery("", $indexTable);
    /**************************************** 开始并发查询 **************************************/
    /*#############  属性  ###############*/
    $sphinx->ResetGroupBy();
    $sphinx->SetGroupBy('feature', SPH_GROUPBY_ATTR, "@count desc");
    $sphinx->SetLimits(0, 200, 200);
    $sphinx->AddQuery("", $indexTable);
    /*#############  省  ###############*/
    $sphinx->ResetGroupBy();
    $sphinx->SetGroupBy('province', SPH_GROUPBY_ATTR, "@count desc");
    $sphinx->SetLimits(0, 20, 20);
    $sphinx->AddQuery("", $indexTable);
    /*#############  市  ###############*/
    $sphinx->ResetGroupBy();
    $sphinx->SetGroupBy('city', SPH_GROUPBY_ATTR, "@count desc");
    $sphinx->SetLimits(0, 20, 20);
    $sphinx->AddQuery("", $indexTable);
    /*#############  品牌  ###############*/
    $sphinx->ResetGroupBy();
    $sphinx->SetGroupBy('brand', SPH_GROUPBY_ATTR, "@count desc");
    $sphinx->SetLimits(0, 20, 20);
    $sphinx->AddQuery("", $indexTable);
    /*#############  4级分类  ###############*/
    //有子分类使用特权产品索引,可以对cate4排序
    if (isset($filterArr["has_children"]) && $filterArr["has_children"] == 1) {
        $sphinx->ResetGroupBy();
        $sphinx->SetGroupBy('cate4', SPH_GROUPBY_ATTR, "@count desc");
        $sphinx->SetLimits(0, 20, 20);
        $sphinx->AddQuery("", $indexTable);
    }
    /*#############  执行  ###############*/
    $batchResult = $sphinx->RunQueries();
    /**************************************** 完成并发查询 **************************************/
    /**************************************** 错误验证 **************************************/
    $error = $sphinx->getLastError();
    if ($error) {
        return $result;
    }
    /**************************************** 结果抽取处理 **************************************/
    if (is_array($batchResult) && count($batchResult) > 0) {
        $result['data'] = $batchResult[0];
        $result['property'] = isset($batchResult[1]) ? $batchResult[1] : array();
        $result['province'] = isset($batchResult[2]) ? $batchResult[2] : array();
        $result['city'] = isset($batchResult[3]) ? $batchResult[3] : array();
        $result['brand'] = isset($batchResult[4]) ? $batchResult[4] : array();
        $result["cate4"] = isset($batchResult[5]) ? $batchResult[5] : array();
    } else {
        return $result;
    }
    $resData = array();
    if (!isset($result['data']['matches'])) {
        $result['data']['matches'] = array();
    }
    foreach ($result['data']['matches'] as $k => $v) {
        $resData[] = array($k, $v['attrs']['cid']);
    }
    $result['total_found'] = $result['data']['total_found'];
    $result['time'] = $result['data']['time'];
    $result['data'] = $resData;
    $result['data'] = sortData($result['data']);
    if ($page > 0) {
        $result["data"] = array_slice($result["data"], ($page - 1) * $perpage, $perpage);
    }
    $result["property"] = !empty($result['property']) ? fomatSphinxData($result['property']) : array();
    $result["province"] = !empty($result['province']) ? fomatSphinxData($result['province']) : array();
    $result["city"] = !empty($result['city']) ? fomatSphinxData($result['city']) : array();
    $result["brand"] = !empty($result['brand']) ? fomatSphinxData($result['brand']) : array();
    $result["cate4"] = !empty($result['cate4']) ? fomatSphinxData($result['cate4']) : array();
    $result["property"] = json_encode($result["property"], JSON_UNESCAPED_UNICODE);
    $result["province"] = json_encode($result["province"], JSON_UNESCAPED_UNICODE);
    $result["city"] = json_encode($result["city"], JSON_UNESCAPED_UNICODE);
    $result["brand"] = json_encode($result["brand"], JSON_UNESCAPED_UNICODE);
    $result["cate4"] = json_encode($result["cate4"], JSON_UNESCAPED_UNICODE);
    return $result;
}
开发者ID:tianyunchong,项目名称:php,代码行数:101,代码来源:sphinxtest.php

示例10: dataFilterFromSphinx

 /**
  * 功能描述  获取筛选
  * @author 吕小虎
  * @datetime ${DATE} ${TIME}
  * @version
  * @param
  * @return
  */
 public function dataFilterFromSphinx($data)
 {
     $this->data = $data;
     //分词
     $this->data['split'] = \Xz\Func\Common\Tools::curlGetContentMs($this->di['config']->base->split . '/wd/' . urlencode($this->data['wd']), 50);
     if (empty($this->data['split'])) {
         $this->data['split'] = $data['wd'];
     }
     $sphinxConfig = $this->di["config"]["combusinessearchsphinxdist"];
     $sphinx = new \SphinxClient();
     $sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
     $indexTable = $sphinxConfig->table;
     $fieldStr = isset($data['field']) ? implode(',', $data['field']) : "id, comname, legal, areaid, uptime";
     $sphinx->SetSelect($fieldStr);
     //一级分类筛选
     if (!empty($this->data['cate1id']) && intval($this->data['cate1id']) > 0) {
         $sphinx->AddQuery('@cate1', $this->data['cate1id'], $indexTable);
     }
     //二级分类筛选
     if (!empty($this->data['cate2id']) && intval($this->data['cate2id']) > 0) {
         $sphinx->AddQuery('@cate2', $this->data['cate2id'], $indexTable);
     }
     //地区筛选
     if (!empty($this->data['areaid']) && intval($this->data['areaid']) > 0) {
         if ($this->data['areaid'] % 10000 == 0) {
             $start = intval($this->data['areaid'] / 10000) * 10000;
             $end = $start + 9999;
             $sphinx->SetFilterRange('areaid', $start, $end, false);
         } elseif ($this->data['areaid'] % 100 == 0) {
             $start = intval($this->data['areaid'] / 100) * 100;
             $end = $start + 99;
             $sphinx->SetFilterRange('areaid', $start, $end, false);
         } else {
             $sphinx->SetFilter('areaid', intval($this->data['areaid']));
         }
     }
     //企业名称和法人搜索
     $sphinx->SetLimits(0, 1, 1);
     $sphinx->AddQuery('@(comname,legal)' . $this->data['split'], $indexTable);
     $sphinx->ResetGroupBy();
     //分类
     $sphinx->SetLimits(0, 20, 20);
     $sphinx->ResetGroupBy();
     $sphinx->SetGroupBy('cate1', SPH_GROUPBY_ATTR, "@count desc");
     $sphinx->AddQuery('@(comname,legal)' . $this->data['split'], $indexTable);
     $sphinx->SetLimits(0, 20, 20);
     $sphinx->ResetGroupBy();
     $sphinx->SetGroupBy('cate2', SPH_GROUPBY_ATTR, "@count desc");
     $sphinx->AddQuery('@(comname,legal)' . $this->data['split'], $indexTable);
     //地区
     $sphinx->SetLimits(0, 35, 20);
     $sphinx->ResetGroupBy();
     $sphinx->SetGroupBy('areaid', SPH_GROUPBY_ATTR, "@count desc");
     $sphinx->AddQuery('@(comname,legal)' . $this->data['split'], $indexTable);
     $result = array();
     $batchResult = $sphinx->RunQueries();
     //        print_r($batchResult);
     $error = $sphinx->getLastError();
     if ($error) {
         $result = array('cate1' => array(), 'cate2' => array(), 'areaid' => array());
     } else {
         //            $result['data'] = $batchResult[0];
         $result['cate1'] = array();
         if (isset($batchResult[1]['matches']) && is_array($batchResult[1]['matches']) && !empty($batchResult[1]['matches'])) {
             foreach ($batchResult[1]['matches'] as $value) {
                 $result['cate1'][$value['attrs']['@groupby']] = $value['attrs']['@count'];
             }
         }
         $result['cate2'] = array();
         if (isset($batchResult[2]['matches']) && is_array($batchResult[2]['matches']) && !empty($batchResult[2]['matches'])) {
             foreach ($batchResult[2]['matches'] as $value) {
                 $result['cate2'][$value['attrs']['@groupby']] = $value['attrs']['@count'];
             }
         }
         $result['areaid'] = array();
         if (isset($batchResult[3]['matches']) && is_array($batchResult[3]['matches']) && !empty($batchResult[3]['matches'])) {
             foreach ($batchResult[3]['matches'] as $value) {
                 $result['areaid'][$value['attrs']['@groupby']] = $value['attrs']['@count'];
             }
         }
     }
     return $result;
 }
开发者ID:tianyunchong,项目名称:php,代码行数:91,代码来源:SearchCombusinessService.php

示例11: getResult

 /**
  * RunQueries() + validate.
  *
  * - Single Query: Resultados da Query
  *
  * - Multi Query:  Array de Resultados das Querys
  *
  * Formato de cada Resultado:
  *
  * <code>
  * //Results
  * array(
  *     array(
  *         'id'     => 12345,
  *         'weight' => 30,
  *         'attrs'  => array(...)
  *     ),
  *     array(
  *         'id'     => 23456,
  *         'weight' => 20,
  *         'attrs'  => array(...)
  *     ),
  *     ...
  * );
  * </code>
  *
  * @param \SphinxClient $sphinxClient
  *
  * @throws \Exception
  *
  * @return array
  */
 protected function getResult(\SphinxClient $sphinxClient)
 {
     $result = $sphinxClient->RunQueries();
     if (false === $result) {
         throw new \Exception($sphinxClient->getLastError());
     }
     if ($sphinxClient->GetLastWarning()) {
         throw new \Exception($sphinxClient->GetLastWarning());
     }
     if (false === $result) {
         throw new \Exception($sphinxClient->getLastError());
     }
     if ($sphinxClient->GetLastWarning()) {
         throw new \Exception($sphinxClient->GetLastWarning());
     }
     //Suporte ao formato inicial de unica query
     if (count($result) === 1) {
         return current($result);
     }
     return $result;
 }
开发者ID:gpupo,项目名称:search,代码行数:53,代码来源:SearchAbstract.php


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