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


PHP SphinxClient::AddQuery方法代码示例

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


在下文中一共展示了SphinxClient::AddQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addQuery

 /**
  * 增加批量查询
  *
  * @param string $query The query string that we are searching for.
  * @param array $indexes The indexes to perform the search on.
  */
 function addQuery($query, array $indexes)
 {
     $indexNames = '';
     foreach ($indexes as &$label) {
         if (isset($this->indexes[$label])) {
             $indexNames .= $this->indexes[$label] . ' ';
         }
     }
     if (!empty($indexNames)) {
         $this->sphinx->AddQuery($query, $indexNames);
     }
 }
开发者ID:290329416,项目名称:guahao,代码行数:18,代码来源:sphinxsearch.php

示例2: SphinxClient

<?php

require "spec/fixtures/sphinxapi.php";
$cl = new SphinxClient();
$cl->SetRetries(10, 20);
$cl->AddQuery('test1');
$cl->SetGroupBy('attr', SPH_GROUPBY_DAY);
$cl->AddQuery('test2');
$cl->RunQueries();
开发者ID:alpbs,项目名称:sphinx,代码行数:9,代码来源:miltiple_queries.php

示例3: SphinxClient

<?php

include 'sphinxapi.php';
$client = new SphinxClient();
$client->SetServer("localhost", 3312);
// simple
$file = fopen("spec/fixtures/data/simple.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
// index
$file = fopen("spec/fixtures/data/index.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ", "edition")]);
fclose($file);
// any
$client->SetMatchMode(SPH_MATCH_ANY);
$file = fopen("spec/fixtures/data/any.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test this ")]);
fclose($file);
$client->SetMatchMode(SPH_MATCH_ALL);
// sort
$client->SetSortMode(SPH_SORT_EXTENDED, "id");
$file = fopen("spec/fixtures/data/sort.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("testing ")]);
fclose($file);
$client->SetSortMode(SPH_SORT_RELEVANCE, "");
// boolean
$client->SetMatchMode(SPH_MATCH_BOOLEAN);
$file = fopen("spec/fixtures/data/boolean.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->SetMatchMode(SPH_MATCH_ALL);
开发者ID:rafasashi,项目名称:gitorious,代码行数:31,代码来源:data_generator.php

示例4: applyQuery

 protected function applyQuery(ESphinxQuery $query)
 {
     $this->applyCriteria($query->getCriteria());
     $this->sphinxClient->AddQuery($query->getText(), $query->getIndexes());
 }
开发者ID:jerrylsxu,项目名称:yii-sphinx,代码行数:5,代码来源:ESphinxConnection.php

示例5: search


//.........这里部分代码省略.........
         }
         $cl->SetFilter('series_attr', $facet_args['facet_series']);
     }
     // Filter by Language
     if (count($facet_args['facet_lang'])) {
         foreach ($facet_args['facet_lang'] as &$facet_lang) {
             $facet_lang = $this->string_poly($facet_lang);
         }
         $cl->SetFilter('lang', $facet_args['facet_lang']);
     }
     // Filter inactive records
     if (!$show_inactive) {
         $cl->SetFilter('active', array('0'), TRUE);
     }
     // Filter by age
     if (count($facet_args['age'])) {
         foreach ($facet_args['age'] as $age_facet) {
             $cl->SetFilter('ages', array($this->string_poly($age_facet)));
         }
     }
     // Filter by availability
     if ($limit_available) {
         $cl->SetFilter('branches', array($this->string_poly($limit_available)));
     }
     $cl->SetRankingMode(SPH_RANK_SPH04);
     $proximity_check = $cl->Query($term, $idx);
     // Quick check on number of results
     // If original match didn't return any results, try a proximity search
     if (empty($proximity_check['matches']) && $bool == FALSE && $term != "*" && $type != "tags") {
         $term = '"' . $term . '"/1';
         $cl->SetMatchMode(SPH_MATCH_EXTENDED);
         $forcedchange = 'yes';
     }
     // Paging/browsing through the result set.
     $sort_limit = 2000;
     if ($offset + $limit > $sort_limit) {
         $sort_limit = $offset + $limit;
     }
     $cl->SetLimits((int) $offset, (int) $limit, (int) $sort_limit);
     // And finally.... we search.
     $cl->AddQuery($term, $idx);
     // CREATE FACETS
     $cl->SetLimits(0, 1000);
     // Up to 1000 facets
     $cl->SetArrayResult(TRUE);
     // Allow duplicate documents in result, for facet grouping
     $cl->SetGroupBy('pub_year', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('pub_decade', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('mat_code', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('branches', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('ages', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('lang', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('series_attr', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('lexile', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $results = $cl->RunQueries();
     // Include descriptors
     $final_result_set['num_hits'] = $results[0]['total_found'];
     if ($results[0]['total'] <= $this->locum_config['api_config']['suggestion_threshold'] || $forcedchange == 'yes') {
         if ($this->locum_config['api_config']['use_yahoo_suggest'] == TRUE) {
             $final_result_set['suggestion'] = $this->yahoo_suggest($term_prestrip);
         }
     }
     // Pull full records out of Couch
     if ($final_result_set['num_hits']) {
         $skip_avail = $this->csv_parser($this->locum_config['format_special']['skip_avail']);
         $bib_hits = array();
         foreach ($results[0]['matches'] as $match) {
             $bib_hits[] = (string) $match['id'];
         }
         $final_result_set['results'] = $this->get_bib_items_arr($bib_hits);
         foreach ($final_result_set['results'] as &$result) {
             $result = $result['value'];
             if ($result['bnum']) {
                 // Get availability (Only cached)
                 $result['status'] = $this->get_item_status($result['bnum'], FALSE, TRUE);
             }
         }
     }
     $final_result_set['facets'] = $this->sphinx_facetizer($results);
     if ($forcedchange == 'yes') {
         $final_result_set['changed'] = 'yes';
     }
     return $final_result_set;
 }
开发者ID:aadl,项目名称:locum,代码行数:101,代码来源:locum-client.php

示例6: sphinx_do_search

function sphinx_do_search($by_date = false, $start = 0, $count = 50)
{
    global $globals;
    $start_time = microtime(true);
    $indices = $_REQUEST['w'] . ' ' . $_REQUEST['w'] . '_delta';
    $cl = new SphinxClient();
    $cl->SetServer($globals['sphinx_server'], $globals['sphinx_port']);
    $cl->SetLimits($start, $count);
    // status, title, tags, url,  content
    $cl->SetWeights(array(0, 4, 2, 1, 1));
    $response = array();
    $queries = array();
    $recorded = array();
    $response['rows'] = 0;
    $response['time'] = 0;
    if (empty($_REQUEST['words'])) {
        return $response;
    }
    $words_array = explode(" ", $_REQUEST['words']);
    $words_count = count($words_array);
    $words = $_REQUEST['words'];
    if ($_REQUEST['t']) {
        $max_date = time();
        $min_date = intval($_REQUEST['t']);
        $cl->SetFilterRange('date', $min_date, $max_date);
    }
    if ($_REQUEST['h']) {
        $max_date = time();
        $min_date = $max_date - intval($_REQUEST['h']) * 3600;
        $cl->SetFilterRange('date', $min_date, $max_date);
    }
    if ($_REQUEST['w'] == 'links' && $_REQUEST['s']) {
        $cl->SetFilter('status', array($_REQUEST['s_id']));
    }
    if ($_REQUEST['u']) {
        $u = new User();
        $u->username = $_REQUEST['u'];
        $u->read();
        $cl->SetFilterRange('user', $u->id, $u->id);
    }
    if ($_REQUEST['w'] == 'links' && $_REQUEST['p']) {
        $f = '@' . $_REQUEST['p'];
    } else {
        $f = '@*';
    }
    if ($by_date || $_REQUEST['o'] == 'date') {
        $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'date');
    } else {
        $cl->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'date');
        //$cl->SetSortMode (SPH_SORT_RELEVANCE);
    }
    $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
    if ($_REQUEST['p'] == 'url') {
        $q = $cl->AddQuery("{$f} \"{$words}\"", $indices);
    } else {
        $q = $cl->AddQuery("{$f} {$words}", $indices);
    }
    array_push($queries, $q);
    // If there are no boolean opertions, add a new search for ANY of the terms
    if (!preg_match('/( and | or | [\\-\\+\\&\\|])/i', $words) && $words_count > 1) {
        $n = 0;
        foreach ($words_array as $w) {
            if ($n > 0) {
                $f .= ' |';
            }
            $f .= " {$w}";
            $n++;
        }
        $q = $cl->AddQuery($f, $indices);
        array_push($queries, $q);
    }
    $results = $cl->RunQueries();
    $n = 0;
    $response['error'] = $results['error'];
    foreach ($queries as $q) {
        $res = $results[$q];
        if (is_array($res["matches"])) {
            $response['rows'] += $res["total_found"];
            // $response['time'] += $res["time"];
            foreach ($res["matches"] as $doc => $docinfo) {
                if (!$recorded[$doc]) {
                    $response['ids'][$n] = $doc;
                    $recorded[$doc] = true;
                    $n++;
                } else {
                    $response['rows']--;
                }
            }
        }
    }
    $response['time'] = microtime(true) - $start_time;
    return $response;
}
开发者ID:brainsqueezer,项目名称:fffff,代码行数:93,代码来源:search.php

示例7: indexAction

 public function indexAction(Application $application, Template $template)
 {
     $template->setParameter('title', 'Форс-о-метр');
     if (array_key_exists('query', $_GET)) {
         $query = $this['query'] = $_GET['query'];
         $search = new SphinxClient();
         $search->SetServer('localhost', 3312);
         $search->SetGroupBy('created_at', SPH_GROUPBY_MONTH);
         // Полный поиск (запрос):
         $search->ResetFilters();
         $search->SetMatchMode(SPH_MATCH_PHRASE);
         $search->AddQuery($query, 'forceometer');
         // Поиск уникальных в месяц (запрос):
         $search->ResetFilters();
         $search->SetMatchMode(SPH_MATCH_PHRASE);
         $search->SetFilter('uniq_m', array(1));
         $search->AddQuery($query, 'forceometer');
         // Поиск уникальных вообще (запрос):
         $search->ResetFilters();
         $search->SetMatchMode(SPH_MATCH_PHRASE);
         $search->SetFilter('uniq_f', array(1));
         $search->AddQuery($query, 'forceometer');
         $query_result = $search->RunQueries();
         // Поиск уникальных постеров месяца (вообще):
         $search->ResetFilters();
         $search->SetMatchMode(SPH_MATCH_FULLSCAN);
         $search->SetFilter('uniq_m', array(1));
         $bare_query = $search->Query('', 'forceometer');
         /*
         		    $search -> ResetFilters();
                     $search -> SetMatchMode(SPH_MATCH_FULLSCAN);
                     $bare_query2 = $search -> Query('', 'forceometer');
         */
         if (!$query_result || $query_result[0]['total_found'] == 0) {
             $this['not_found'] = 1;
             return true;
         }
         $result = array('posts' => array(), 'posters' => array(), 'uniq_m' => array(), 'uniq_f' => array());
         for ($y = 2009; $y <= date('Y'); $y++) {
             for ($m = 1; $m <= 12; $m++) {
                 // Пропуск несуществующих дат и текущего месяца:
                 if ($y == 2009 && $m < 3) {
                     continue;
                 }
                 if ($y == date('Y') && $m >= date('m')) {
                     break;
                 }
                 $stamp = $y . '-' . ($m < 10 ? '0' . $m : $m) . '-01';
                 $result['posts'][$stamp] = 0;
                 $result['posters'][$stamp] = 0;
                 $result['uniq_m'][$stamp] = 0;
                 $result['uniq_f'][$stamp] = 0;
             }
         }
         // Проходим результаты:
         if ($query_result[0]['matches']) {
             foreach ($query_result[0]['matches'] as $match) {
                 $date = $match['attrs']['@groupby'];
                 $stamp = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-01';
                 if (array_key_exists($stamp, $result['posts'])) {
                     $result['posts'][$stamp] = $match['attrs']['@count'];
                 }
             }
         }
         if ($bare_query['matches']) {
             foreach ($bare_query['matches'] as $match) {
                 $date = $match['attrs']['@groupby'];
                 $stamp = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-01';
                 if (array_key_exists($stamp, $result['posters'])) {
                     $result['posters'][$stamp] = $match['attrs']['@count'];
                 }
             }
         }
         if ($query_result[1]['matches']) {
             foreach ($query_result[1]['matches'] as $match) {
                 $date = $match['attrs']['@groupby'];
                 $stamp = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-01';
                 if (array_key_exists($stamp, $result['uniq_m'])) {
                     $result['uniq_m'][$stamp] = $match['attrs']['@count'];
                 }
             }
         }
         /*
                     if ($bare_query2['matches']) {
                         foreach($bare_query2['matches'] as $match) {
                             $date = $match['attrs']['@groupby'];
                             $stamp = substr($date, 0, 4) .'-'. substr($date, 4, 2) .'-01';
         
                             if (array_key_exists($stamp, $result['uniq_f']))
                                 $result['uniq_f'][$stamp] = $match['attrs']['@count'];
                         }
                     }*/
         foreach ($result['posts'] as $date => $count) {
             if ($count == 0) {
                 unset($result['posts'][$date]);
                 unset($result['posters'][$date]);
                 unset($result['uniq_f'][$date]);
                 unset($result['uniq_m'][$date]);
             }
         }
//.........这里部分代码省略.........
开发者ID:postman0,项目名称:1chan,代码行数:101,代码来源:forceometer.controller.php

示例8: sphinx_get_search_link

function sphinx_get_search_link($by_date = false, $start = 0, $count = 50)
{
    global $globals;
    $cl = new SphinxClient();
    $cl->SetServer($globals['sphinx_server'], $globals['sphinx_port']);
    $cl->SetLimits($start, $count);
    // status, title, tags, url,  content
    $cl->SetWeights(array(0, 4, 2, 1, 1));
    $response = array();
    $queries = array();
    $recorded = array();
    $response['rows'] = 0;
    $response['time'] = 0;
    $words = $_REQUEST['q'] = trim(substr(strip_tags($_REQUEST['q']), 0, 250));
    if (empty($words)) {
        return $response;
    }
    if (preg_match('/^ *(\\w+): *(.*)/', $words, $matches)) {
        $prefix = $matches[1];
        $words = $matches[2];
    }
    if (preg_match('/^http[s]*/', $prefix)) {
        // It's an url search
        $words = "{$prefix}:{$words}";
        $prefix = false;
        $field = 'url';
    }
    if ($prefix) {
        switch ($prefix) {
            case 'date':
                $by_date = true;
                break;
            case 'url':
                $field = 'url';
                break;
            case 'title':
                $field = 'title';
                break;
            case 'tag':
            case 'tags':
                $field = 'tags';
                break;
        }
    }
    $words_count = count(explode(" ", $words));
    if ($field) {
        $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'date');
        $cl->SetMatchMode(SPH_MATCH_EXTENDED);
        $q = $cl->AddQuery("@{$field} \"{$words}\"", 'main delta');
        array_push($queries, $q);
    } elseif ($words_count < 2 || $by_date) {
        $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'date');
        $cl->SetMatchMode(SPH_MATCH_ALL);
        $q = $cl->AddQuery($words, 'main delta');
        array_push($queries, $q);
    } else {
        if ($words_count > 2) {
            $cl->SetMatchMode(SPH_MATCH_PHRASE);
            //$cl->SetSortMode (SPH_SORT_ATTR_DESC, 'date');
            $cl->SetSortMode(SPH_SORT_RELEVANCE);
            $q = $cl->AddQuery($words, 'main delta');
            array_push($queries, $q);
        }
        $cl->SetMatchMode(SPH_MATCH_ALL);
        $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'date');
        //$cl->SetSortMode (SPH_SORT_RELEVANCE);
        $q = $cl->AddQuery($words, 'main delta');
        array_push($queries, $q);
        $cl->SetMatchMode(SPH_MATCH_ANY);
        $cl->SetSortMode(SPH_SORT_RELEVANCE);
        $q = $cl->AddQuery($words, 'main delta');
        array_push($queries, $q);
    }
    $results = $cl->RunQueries();
    $n = 0;
    $response['error'] = $results['error'];
    foreach ($queries as $q) {
        $res = $results[$q];
        if (is_array($res["matches"])) {
            $response['rows'] += $res["total_found"];
            $response['time'] += $res["time"];
            foreach ($res["matches"] as $doc => $docinfo) {
                if (!$recorded[$doc]) {
                    $response['ids'][$n] = $doc;
                    $recorded[$doc] = true;
                    $n++;
                } else {
                    $response['rows']--;
                }
            }
        }
    }
    return $response;
}
开发者ID:brainsqueezer,项目名称:fffff,代码行数:94,代码来源:sphinx.php

示例9: CsGetData

function CsGetData($index = '*', $words = '卫浴', $wheres = '', $orderby = 'id desc', $firstRow = 0, $listRows = 10, $timeout = 1, $host = 'localhost', $port = 9312)
{
    require C('INTERFACE_PATH') . 'coreseek/api/sphinxapi.php';
    $mem = new Memcache();
    $result = $mem->connect('localhost', 11211);
    $mem_key = 'coreseek_config';
    if ($mem->get($mem_key)) {
        $config = $mem->get($mem_key);
    } else {
        $config = (require C('ROOT_SITE_DIR') . 'coreseek_config.php');
        $mem->set($mem_key, $config, 0, 86400 * 365);
    }
    if (date('H') > 5 && date('H') < 6) {
        $host = $config[1]['host'];
        $port = $config[1]['port'];
    } else {
        $host = $config[1]['host'];
        $port = $config[1]['port'];
    }
    $cl = new SphinxClient();
    $cl->SetServer($host, $port);
    $cl->SetArrayResult(true);
    $cl->SetConnectTimeout($timeout);
    if ($wheres) {
        foreach ($wheres as $where) {
            $cl->SetFilter($where['field'], array($where['value']), $where['status']);
        }
    }
    $cl->SetSortMode(SPH_SORT_EXTENDED, $orderby);
    $cl->SetLimits($firstRow, $listRows);
    $cl->AddQuery($words, $index);
    $result = $cl->RunQueries();
    return $result;
}
开发者ID:8yong8,项目名称:vshop,代码行数:34,代码来源:function.php

示例10: QuerySearch

 protected function QuerySearch($index, $sort, $order, $port = 9312, $host = 'localhost')
 {
     $sphinx = new SphinxClient();
     $sphinx->SetServer($host, $port);
     $sphinx->SetConnectTimeout(1);
     $sphinx->SetArrayResult(true);
     $sphinx->SetLimits(0, static::LIMIT_SEARCH);
     $sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
     $sphinx->SetSortMode($order, $sort);
     // Limit results to a certain period
     if (!is_null($this->search_range)) {
         $sphinx->SetFilterRange($sort, time() - $this->search_range, time());
     }
     // Check for multi-query search
     if (is_array($this->search)) {
         foreach ($this->search as $query) {
             if (!empty($query)) {
                 $sphinx->AddQuery($this->FilterSearch($query), $index);
             }
         }
         $result = $sphinx->RunQueries();
     } else {
         $result = $sphinx->Query($this->FilterSearch($this->search), $index);
     }
     if ($result === false) {
         throw new ErrorException('Search failed: ' . $sphinx->GetLastError());
     }
     // Return result
     $ids = array();
     $ids[] = 0;
     // Make IN() valid even if Sphinx returned nothing
     if (is_array($this->search)) {
         // Merge results from multi-query search
         foreach ($result as $r) {
             if (isset($r['matches'])) {
                 foreach ($r['matches'] as $match) {
                     $ids[] = $match['id'];
                 }
             }
         }
     } elseif (isset($result['matches'])) {
         foreach ($result['matches'] as $match) {
             $ids[] = $match['id'];
         }
     }
     return $ids;
 }
开发者ID:Strikethegod,项目名称:fanzub,代码行数:47,代码来源:class.framework.php

示例11: 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

示例12: SphinxClient

<?php

require "spec/fixtures/sphinxapi.php";
$cl = new SphinxClient();
$cl->AddQuery('wifi', 'fakeindex');
$cl->RunQueries();
开发者ID:alpbs,项目名称:sphinx,代码行数:6,代码来源:run_queries_error.php

示例13: SphinxClient

<?php

require "spec/fixtures/sphinxapi.php";
$cl = new SphinxClient();
$cl->AddQuery('wifi', 'test1');
$cl->AddQuery('gprs', 'test1');
$cl->RunQueries();
开发者ID:alpbs,项目名称:sphinx,代码行数:7,代码来源:run_queries.php

示例14: fromSpecialSphinx

 /**
  * 特殊的搜索,用于供应商查询收录,产品查询收录等
  *
  * @Author   tianyunzi
  * @DateTime 2015-12-23T15:16:46+0800
  * @param    [type]                   $data [description]
  * @return   [type]                         [description]
  */
 public function fromSpecialSphinx($data)
 {
     $this->data = $data;
     $this->data["split"] = "@comname " . $this->data["wd"];
     $sphinxConfig = $this->di["config"]["prosearchd"];
     $sphinx = new \SphinxClient();
     $sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
     //$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
     $indexTable = "product_distri";
     //TODO 索引范围
     if (isset($this->data["cate1"]) && $this->data["cate1"] > 0) {
         $indexTable = "product_distri_" . $this->data["cate1"];
     }
     if (!isset($this->data['cateid']) && isset($this->data['cate3'])) {
         $this->data['cateid'] = $this->data['cate3'];
     }
     $sphinx->SetSelect("id, cid, brand, feature, province, city");
     if (isset($this->data["pid"]) && $this->data["pid"] > 0) {
         $this->data["split"] = "";
         $sphinx->SetFilter("id", array($this->data["pid"]), false);
     }
     if (isset($this->data["cid"]) && $this->data["cid"] > 0) {
         $this->data["split"] = "";
         $sphinx->SetFilter("cid", array($this->data["cid"]), false);
     }
     if (!empty($this->data['cateid']) && intval($this->data['cateid']) > 0) {
         $sphinx->SetFilter('cate3', array(intval($this->data['cateid'])), false);
     }
     if (!empty($this->data['brand']) && intval($this->data['brand']) > 0) {
         $sphinx->SetFilter('brand', array(intval($this->data['brand'])), false);
     }
     if (!empty($this->data['province']) && intval($this->data['province']) > 0) {
         $sphinx->SetFilter('province', array(intval($this->data['province'])), false);
     }
     if (!empty($this->data['city']) && intval($this->data['city']) > 0) {
         $sphinx->SetFilter('city', array(intval($this->data['city'])), false);
     }
     if (!empty($this->data['iscertify']) && intval($this->data['iscertify']) > 0) {
         $sphinx->SetFilter('is_gccertify', array(intval($this->data['iscertify'])), false);
     }
     if (!empty($this->data['isprice']) && intval($this->data['isprice']) > 0) {
         $sphinx->SetFilterRange('price', 1, 9999999, false);
     }
     if (!empty($this->data['feature'])) {
         $featureArr = explode('_', $this->data['feature']);
         foreach ($featureArr as $value) {
             $sphinx->SetFilter('feature', array(intval($value)), false);
         }
     }
     if (!empty($this->data['sort'])) {
         switch ($this->data['sort']) {
             case 1:
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'tradenum DESC');
                 break;
             case 2:
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'visitnum DESC');
                 //访问量/热度
                 break;
             case 3:
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'price DESC');
                 break;
             case 4:
                 $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'price ASC');
                 break;
             case 6:
                 $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);
//.........这里部分代码省略.........
开发者ID:tianyunchong,项目名称:php,代码行数:101,代码来源:SearchProService.php

示例15: sphinxList

function sphinxList($filterArr, $page = 0)
{
    $result = array('data' => array(), 'cate4' => array(), 'property' => array(), 'province' => array(), 'city' => array(), 'brand' => array(), 'total_found' => 0, 'time' => 0);
    $perpage = isset($filterArr['perpage']) && $filterArr['perpage'] ? $filterArr['perpage'] : 20;
    $sphinxConfig = array('host' => '172.17.17.105', 'port' => 9020);
    $sphinx = new \SphinxClient();
    $sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
    if (isset($filterArr["has_children"]) && $filterArr["has_children"] == 1) {
        $indexTable = "product_distri_special";
    } elseif (isset($filterArr['cate1']) && $filterArr['cate1']) {
        $indexTable = "product_distri_" . $filterArr["cate1"];
    } else {
        $indexTable = "product_m_distri";
    }
    $gcdweight = "weight()+IF(id>900000000, tradenum*100, 0)+inquirynum*20+star*2+basescore*5+creditscore+IF(is_op=1, all_uv*10+all_pv, 0)+IF(id>900000000, weight()*0.1, 0) as gcpdweight";
    if (isset($filterArr["has_children"]) && $filterArr["has_children"] == 1) {
        $sphinx->SetSelect("id, cid, brand, cate4, feature, province, city, {$gcdweight}");
    } else {
        $sphinx->SetSelect("id, cid, brand, feature, province, city, {$gcdweight}");
    }
    /**************************************** 过滤模块 ******************************************/
    /* 分类过滤 */
    if (isset($filterArr['cate3']) && isset($filterArr['cate2to3'])) {
        $sphinx->SetFilter('cate2', array(intval($filterArr["cate3"])), false);
    } elseif (isset($filterArr['cate3'])) {
        $sphinx->SetFilter('cate3', array(intval($filterArr["cate3"])), false);
    }
    /* 是否通过工厂认证 */
    if (isset($filterArr['filters']['iscertify']) && $filterArr['filters']['iscertify'] > 0) {
        $sphinx->SetFilter('is_gccertify', array($filterArr['filters']['iscertify']), false);
    }
    /* 是否显示价格 */
    if (isset($filterArr['filters']['isprice']) && $filterArr['filters']['isprice'] > 0) {
        $sphinx->SetFilterRange('price', 1, 9999999, false);
    }
    /* 省过滤 */
    if (!empty($filterArr['filters']['province']) && is_numeric($filterArr['filters']['province'])) {
        $sphinx->SetFilter('province', array(intval($filterArr['filters']['province'])), false);
    }
    /* 市过滤 */
    if (!empty($filterArr['filters']['city']) && is_numeric($filterArr['filters']['city'])) {
        $sphinx->SetFilter('city', array(intval($filterArr['filters']['city'])), false);
    }
    /* 品牌过滤 */
    if (isset($filterArr['filters']['brand']) && $filterArr['filters']['brand'] > 0) {
        $sphinx->SetFilter('brand', array(intval($filterArr['filters']['brand'])), false);
    }
    /* 属性过滤 */
    if (isset($filterArr['filters']['feature']) && $filterArr['filters']['feature']) {
        $featureArr = explode('_', $filterArr['filters']['feature']);
        foreach ($featureArr as $value) {
            $sphinx->SetFilter('feature', array(intval($value)), false);
        }
    }
    /***************************************** 过滤结束 ******************************************/
    /***************************************** 排序 *********************************************/
    $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);
//.........这里部分代码省略.........
开发者ID:tianyunchong,项目名称:php,代码行数:101,代码来源:sphinxtest.php


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