本文整理汇总了PHP中SphinxClient::SetSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetSelect方法的具体用法?PHP SphinxClient::SetSelect怎么用?PHP SphinxClient::SetSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setSelect
/**
* Sets the select clause, listing specific attributes to fetch, and expressions to compute and fetch.
*
* @param $clause SQL-like clause.
* @return SphinxSearch_Abstract_List
* @throws Exception
*/
public function setSelect($clause)
{
$result = $this->SphinxClient->SetSelect($clause);
if ($result === false) {
throw new Exception("Error on setting select \"" . $clause . "\":\n" . $this->SphinxClient->GetLastError());
}
return $this;
}
示例2: resetClient
protected function resetClient()
{
$this->sphinxClient->ResetFilters();
$this->sphinxClient->ResetGroupBy();
$this->sphinxClient->ResetOverrides();
$this->sphinxClient->SetLimits(0, 20);
$this->sphinxClient->SetArrayResult(true);
$this->sphinxClient->SetFieldWeights(array());
$this->sphinxClient->SetIDRange(0, 0);
$this->sphinxClient->SetIndexWeights(array());
$this->sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$this->sphinxClient->SetRankingMode(SPH_RANK_NONE);
$this->sphinxClient->SetSortMode(SPH_SORT_RELEVANCE, "");
$this->sphinxClient->SetSelect("*");
}
示例3: MakeSuggestion
function MakeSuggestion($keyword)
{
$trigrams = BuildTrigrams($keyword);
$query = "\"{$trigrams}\"/1";
$len = strlen($keyword);
$delta = LENGTH_THRESHOLD;
$cl = new SphinxClient();
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetRankingMode(SPH_RANK_WORDCOUNT);
$cl->SetFilterRange("len", $len - $delta, $len + $delta);
$cl->SetSelect("*, @weight+{$delta}-abs(len-{$len}) AS myrank");
$cl->SetSortMode(SPH_SORT_EXTENDED, "myrank DESC, freq DESC");
$cl->SetArrayResult(true);
// pull top-N best trigram matches and run them through Levenshtein
$cl->SetLimits(0, TOP_COUNT);
$res = $cl->Query($query, "suggest");
if (!$res || !$res["matches"]) {
return false;
}
if (SUGGEST_DEBUG) {
print "--- DEBUG START ---\n";
foreach ($res["matches"] as $match) {
$w = $match["attrs"]["keyword"];
$myrank = @$match["attrs"]["myrank"];
if ($myrank) {
$myrank = ", myrank={$myrank}";
}
// FIXME? add costs?
// FIXME! does not work with UTF-8.. THIS! IS!! PHP!!!
$levdist = levenshtein($keyword, $w);
print "id={$match['id']}, weight={$match['weight']}, freq={$match[attrs][freq]}{$myrank}, word={$w}, levdist={$levdist}\n";
}
print "--- DEBUG END ---\n";
}
// further restrict trigram matches with a sane Levenshtein distance limit
foreach ($res["matches"] as $match) {
$suggested = $match["attrs"]["keyword"];
if (levenshtein($keyword, $suggested) <= LEVENSHTEIN_THRESHOLD) {
return $suggested;
}
}
return $keyword;
}
示例4: SphinxClient
<?php
require "sphinxapi.php";
$cl = new SphinxClient();
$cl->SetSelect('attr1, attr2');
$cl->Query('query');
示例5: sphinxKeyword
/**
* 检索关键词是否在库中存在
* @param type $splitKeywords
*/
public function sphinxKeyword($splitKeywords)
{
$sphinxKeywords = $this->getSplitWd($splitKeywords);
$sphinxConfig = array("host" => "172.17.17.105", "port" => 9020);
$sphinx = new \SphinxClient();
$sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
$sphinx->SetSelect("id");
$sphinx->SetLimits(0, 1, 1);
$batchResult = $sphinx->query($sphinxKeywords, "product_distri");
if (isset($batchResult["total_found"]) && $batchResult["total_found"] > 0) {
return true;
}
return false;
}
示例6:
$cl->SetFilter($filter, $filtervals);
}
if ($groupby) {
$cl->SetGroupBy($groupby, SPH_GROUPBY_ATTR, $groupsort);
}
if ($sortby) {
$cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
}
if ($sortexpr) {
$cl->SetSortMode(SPH_SORT_EXPR, $sortexpr);
}
if ($distinct) {
$cl->SetGroupDistinct($distinct);
}
if ($select) {
$cl->SetSelect($select);
}
if ($limit) {
$cl->SetLimits(0, $limit, $limit > 1000 ? $limit : 1000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($q, $index);
////////////////
// print me out
////////////////
if ($res === false) {
print "Query failed: " . $cl->GetLastError() . ".\n";
} else {
if ($cl->GetLastWarning()) {
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
示例7: 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;
}
示例8: run
public function run($subject_id, $clean = true, $query_offset = 0, $from, $to)
{
$this->load->helper('sphinxapi');
$this->load->helper('mood');
// skip if matching_status is "matching"
$matching_status = $this->custom_model->get_value('subject', 'matching_status', $subject_id);
if ($matching_status == 'matching') {
echo "subject is matching";
return false;
}
// flag subject as matching.. do other bot runs this queue.
//$this->db->update('subject',array('matching_status'=>'matching'),array('id'=>$subject_id));
// clear all match record for this subject
$config['hostname'] = "192.168.1.102";
$config['username'] = "root";
$config['password'] = "usrobotic";
$config['database'] = "thothconnect";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$thothconnect_db = $this->load->database($config, true);
$query = $this->db->query("SELECT client_id FROM subject WHERE id = " . $subject_id);
$row = $query->row();
$client_id = $row->client_id;
if ($clean) {
$thothconnect_db->delete('website_c' . $client_id, array('subject_id' => $subject_id));
$thothconnect_db->delete('twitter_c' . $client_id, array('subject_id' => $subject_id));
$thothconnect_db->delete('facebook_c' . $client_id, array('subject_id' => $subject_id));
}
//
// begin re-matching this subject
//
// get search string from subject_id
$query = $this->custom_model->get_value('subject', 'query', $subject_id);
// sphinx init
$cl = new SphinxClient();
$q = $query;
$sql = "";
$mode = SPH_MATCH_EXTENDED;
$host = "192.168.1.102";
$port = 9312;
$index = "*";
$groupby = "";
$groupsort = "@group desc";
$filter = "group_id";
$filtervals = array();
$distinct = "";
$sortby = "@id ASC";
$sortexpr = "";
$offset = $query_offset;
$limit = 1000000;
$ranker = SPH_RANK_PROXIMITY_BM25;
$select = "";
echo 'limit=' . $limit . ' offset=' . $offset . PHP_EOL;
//Extract subject keyword from search string
$keywords = get_keywords($q);
////////////
// do query
////////////
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetArrayResult(true);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
// if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
// if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ($sortby) {
$cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
}
// if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ($distinct) {
$cl->SetGroupDistinct($distinct);
}
if ($select) {
$cl->SetSelect($select);
}
if ($limit) {
$cl->SetLimits(0, $limit, $limit > 1000000 ? $limit : 1000000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($q, $index);
//$res = true;
////////////
// do Insert to DB
////////////
// Current matching
$current_matching = array();
/*$query_matchs = $this->db->get_where('matchs',array('subject_id'=>$subject_id));
if($query_matchs->num_rows() > 0)
{
echo PHP_EOL.'currents matching :'.$query_matchs->num_rows();
foreach($query_matchs->result() as $match)
{
$current_matching[] = $match->post_id;
}
//.........这里部分代码省略.........
示例9: fopen
// keywords_without_hits
$file = fopen("spec/fixtures/data/keywords_without_hits.bin", "w");
fwrite($file, $client->BuildKeywords("pat", "people", false));
fclose($file);
// keywords_with_hits
$file = fopen("spec/fixtures/data/keywords_with_hits.bin", "w");
fwrite($file, $client->BuildKeywords("pat", "people", true));
fclose($file);
// overrides
$client->SetOverride("rating", SPH_ATTR_FLOAT, array(1 => 10.0));
$file = fopen("spec/fixtures/data/overrides.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->ResetOverrides();
// select
$client->SetSelect("selecting");
$file = fopen("spec/fixtures/data/select.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->SetSelect("*");
// filter_array
$client->SetFilter("field", array(1, 2, 3));
$file = fopen("spec/fixtures/data/filter_array.bin", "w");
fwrite($file, $client->FilterOutput());
fclose($file);
$client->ResetFilters();
// filter_array_exclude
$client->SetFilter("field", array(1, 2, 3), true);
$file = fopen("spec/fixtures/data/filter_array_exclude.bin", "w");
fwrite($file, $client->FilterOutput());
fclose($file);
示例10: select
/**
* @brief set select-list (attributes or expressions), SQL-like syntax - 'expression'
* @param string $select
* @return $this chain
*/
public function select($select)
{
$this->criteria->select = $select;
$this->client->SetSelect($select);
return $this;
}
示例11: getList
/**
* ¬озвращает список публичных типовых услуг по заданным услови¤м и пагинацией
*
* @return array
*/
public function getList($excluded_ids = array())
{
$criteria = array($this->category_id, $this->city_id, $this->country_id, $this->keywords, $this->limit, $this->offset, $this->price_ranges, $this->price_max, $this->order, $excluded_ids, $this->user_id);
$membuf = new memBuff();
$memkey = __METHOD__ . '#' . md5(serialize($criteria));
if (false !== ($result = $membuf->get($memkey)) && is_release()) {
return $result;
}
$sort = $this->getSort();
# @see http://sphinxsearch.com/forum/view.html?id=11538 about city = x or country = y
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer(SEARCHHOST, SEARCHPORT);
$sphinxClient->SetLimits($this->offset, $this->limit, 20000);
$sphinxClient->SetSortMode(SPH_SORT_EXTENDED, $sort);
$sphinxClient->SetFieldWeights(array('title' => 2, 'extra_title' => 1));
//$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$selectExpression = '*';
// все колонки
if ($this->user_id) {
$selectExpression .= ", IF(user_id = {$this->user_id}, 1, 0) as match_user";
$sphinxClient->setFilter('match_user', array(1));
}
if ($this->category_id) {
$selectExpression .= ", IF(category_id = {$this->category_id} or category_parent_id = {$this->category_id}, 1, 0) as match_category";
$sphinxClient->setFilter('match_category', array(1));
}
if ($this->country_id) {
$selectExpression .= ", IF(user_country_id = {$this->country_id} or country_id = {$this->country_id}, 1, 0) as match_country";
$sphinxClient->setFilter('match_country', array(1));
}
if ($this->city_id) {
$selectExpression .= ", IF(user_city_id = {$this->city_id} or city_id = {$this->city_id}, 1, 0) as match_city";
$sphinxClient->setFilter('match_city', array(1));
}
if (count($this->price_ranges)) {
$match_price_exprs = array();
foreach ($this->getPriceRanges() as $i => $price_range) {
if (!isset($this->price_ranges[$i])) {
continue;
}
$match_price_exprs[] = "price_{$i} = 1";
}
$match_price_exprs = implode(' or ', $match_price_exprs);
$selectExpression .= ", IF({$match_price_exprs}, 1, 0) as match_price";
$sphinxClient->setFilter('match_price', array(1));
}
if ($this->price_max > 0) {
$selectExpression .= ", IF(price <= {$this->price_max}, 1, 0) as match_price_max";
$sphinxClient->setFilter('match_price_max', array(1));
}
$searchString = '';
if (!empty($this->keywords)) {
$keywords = implode(' ', array_filter(preg_split('/\\s*,\\s*/', $this->keywords)));
$searchString = trim($keywords);
//$searchString = $this->GetSphinxKeyword($searchString);
$sphinxClient->SetMatchMode(SPH_MATCH_ANY);
//SPH_MATCH_EXTENDED2);
}
if (count($excluded_ids)) {
$sphinxClient->setFilter('tservice_id', $excluded_ids, true);
}
$sphinxClient->SetSelect($selectExpression);
$queryResult = $sphinxClient->query($searchString, "tservices;delta_tservices");
//echo '<pre>error: ', $sphinxClient->GetLastError(), '</pre>';
//echo '<pre>warn : ', $sphinxClient->GetLastWarning(), '</pre>';
$list = array();
$total = 0;
if (isset($queryResult['matches'])) {
foreach ($queryResult['matches'] as $id => $row) {
$row['attrs']['id'] = $id;
$list[] = $row['attrs'];
}
$total = $queryResult['total_found'] < $queryResult['total'] ? $queryResult['total_found'] : $queryResult['total'];
}
$result = array('list' => $list, 'total' => $total);
if ($this->_ttl) {
$membuf->set($memkey, $result, $this->_ttl);
}
return $result;
}
示例12: 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;
}
示例13: sphinx
/**
* 从sphinx获取数据 不带分组筛选
* @author 吕小虎
* @datetime
* @return
*/
public function sphinx($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']));
// $sphinx->SetServer('172.17.17.103', 9111);
$indexTable = $sphinxConfig->table;
$gcdweight = "weight()+IF(hasgccid>0, 100, 0) as cbweight";
$fieldStr = "id, comname, legal, areaid, uptime,{$gcdweight}";
$sphinx->SetSelect($fieldStr);
//排序 有gccid的靠前
if (isset($data['order']) && !empty($data['order'])) {
$sphinx->SetSortMode(SPH_SORT_EXTENDED, $data['order']);
} else {
$sphinx->SetSortMode(SPH_SORT_EXTENDED, 'cbweight DESC');
}
//搜某个字段
$t = isset($this->data['t']) ? trim($this->data['t']) : '';
//搜索类型 app/common
$type = isset($this->data['type']) ? $this->data['type'] : 'common';
//一级分类筛选
if (!empty($this->data['cate1id']) && intval($this->data['cate1id']) > 0) {
$sphinx->SetFilter('cate1', array(intval($this->data['cate1id'])), false);
}
//二级分类筛选
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) {
//.........这里部分代码省略.........
示例14: SphinxClient
<?php
/**
* User: yunsong
* Date: 3/12/16
* Time: 10:46 AM
* Email:awebc@qq.com
*/
require "../../common/components/SphinxClient.php";
$sphinx = new SphinxClient();
$sphinx->SetServer("127.0.0.1", 9312);
// $sphinx->SetMatchMode(6);// SPH_MATCH_EXTENDED2
$sphinx->SetSelect("id");
$sphinx->SetArrayResult(true);
$sphinx->SetLimits(0, 20);
$res = $sphinx->Query($query, "feeds");
echo '<pre>';
print_r($res['matches']);
print_r($res);
print_r($sphinx->GetLastError());
print_r($sphinx->GetLastWarning());
echo '</pre>';
echo 1;
示例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);
//.........这里部分代码省略.........