本文整理汇总了PHP中SphinxClient::SetGroupDistinct方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetGroupDistinct方法的具体用法?PHP SphinxClient::SetGroupDistinct怎么用?PHP SphinxClient::SetGroupDistinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetGroupDistinct方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyCriteria
protected function applyCriteria(ESphinxSearchCriteria $criteria)
{
$this->applyMatchMode($criteria->matchMode);
$this->applyRankMode($criteria);
if ($criteria->sortMode == ESphinxSort::EXTENDED) {
$orders = '';
if ($orderArray = $criteria->getOrders()) {
$fields = array();
foreach ($orderArray as $attr => $type) {
$fields[] = $attr . ' ' . $type;
}
$orders = implode(', ', $fields);
}
$this->applySortMode($criteria->sortMode, $orders);
} else {
$this->applySortMode($criteria->sortMode, $criteria->getSortBy());
}
// apply select
if (strlen($criteria->select)) {
$this->sphinxClient->SetSelect($criteria->select);
}
// apply limit
if ($criteria->limit) {
$this->sphinxClient->SetLimits($criteria->offset, $criteria->limit, $criteria->maxMatches, $criteria->cutOff);
}
// apply group
if ($criteria->groupBy) {
$this->sphinxClient->SetGroupBy($criteria->groupBy, $criteria->groupByFunc, $criteria->groupBySort);
}
if ($criteria->groupDistinct) {
$this->sphinxClient->SetGroupDistinct($criteria->groupDistinct);
}
// apply id range
if ($criteria->getIsIdRangeSetted()) {
$this->sphinxClient->SetIDRange($criteria->getMinId(), $criteria->getMaxId());
}
// apply weights
$this->applyFieldWeights($criteria->getFieldWeights());
$this->applyIndexWeights($criteria->getIndexWeights());
$this->applyFilters($criteria->getFilters());
$this->applyRanges($criteria->getRangeFilters());
$this->sphinxClient->SetMaxQueryTime($criteria->queryTimeout !== null ? $criteria->queryTimeout : $this->_queryTimeout);
if (VER_COMMAND_SEARCH >= 0x11d) {
$this->applyOptions($criteria);
}
}
示例2: do_query
function do_query($search_str)
{
//$tmp_var = array(array('itemName' => "test1"), array('itemName' => "test2"), array('itemName' => "test3"));
//echo implode(",",tmp_var);
//echo json_encode($tmp_var);
//return tmp_var;
$q = "";
$sql = "";
$mode = SPH_MATCH_ALL;
$host = "localhost";
$port = 9312;
$index = "*";
$groupby = "";
$groupsort = "@group desc";
$filter = "group_id";
$filtervals = array();
$distinct = "";
$sortby = "";
$sortexpr = "";
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$select = "*";
$cl = new SphinxClient();
$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 > 1000 ? $limit : 1000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($search_str, $index);
//return $res;
if (is_array($res["matches"])) {
$results = array();
$n = 1;
//print "Matches:\n";
foreach ($res["matches"] as $docinfo) {
//print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";
$attr_array = array();
$results[$docinfo[id]];
foreach ($res["attrs"] as $attrname => $attrtype) {
$value = $docinfo["attrs"][$attrname];
if ($attrtype == SPH_ATTR_MULTI || $attrtype == SPH_ATTR_MULTI64) {
$value = "(" . join(",", $value) . ")";
} else {
if ($attrtype == SPH_ATTR_TIMESTAMP) {
$value = date("Y-m-d H:i:s", $value);
}
}
$attr_array[$attrname] = $value;
//print $value;
}
$results[$docinfo[id]] = $attr_array;
$n++;
//print implode("",$results)."\n";
}
return $results;
}
}
示例3: array
fclose($file);
$client->SetMatchMode(SPH_MATCH_ALL);
// filter
$client->SetFilter("id", array(10, 100, 1000));
$file = fopen("spec/fixtures/data/filter.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->ResetFilters();
// group
$client->SetGroupBy("id", SPH_GROUPBY_ATTR, "id");
$file = fopen("spec/fixtures/data/group.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->ResetGroupBy();
// distinct
$client->SetGroupDistinct("id");
$file = fopen("spec/fixtures/data/distinct.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->ResetGroupBy();
// weights
$client->SetWeights(array(100, 1));
$file = fopen("spec/fixtures/data/weights.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->SetWeights(array());
// anchor
$client->SetGeoAnchor("latitude", "longitude", 10.0, 95.0);
$file = fopen("spec/fixtures/data/anchor.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
示例4:
$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 > 1000 ? $limit : 1000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($q, $index);
////////////////
// print me out
////////////////
if ($res === false) {
print "Query failed: " . $cl->GetLastError() . ".\n";
} else {
示例5: 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;
}
//.........这里部分代码省略.........
示例6: SphinxClient
<?php
require "spec/fixtures/sphinxapi.php";
$cl = new SphinxClient();
$cl->SetGroupBy('attr', SPH_GROUPBY_DAY);
$cl->SetGroupDistinct('attr');
$cl->Query('query');
示例7: 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
if ($clean) {
$this->db->delete('matchs', 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);
////////////
// 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;
}
}
// set matching date range from-to
$from = strtotime($from);
$to = strtotime($to);
// Search and Update
if ($res === false) {
echo "Query failed: " . $cl->GetLastError() . ".\n";
} else {
if ($cl->GetLastWarning()) {
echo "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
echo "Query '{$q}' \nretrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n";
if ($res['total'] == 0) {
echo "no result<br/>\n";
} else {
if ($res['total'] > $limit + $offset) {
$this->run($subject_id, $limit + $offset);
} else {
echo "Updating...";
foreach ($res["matches"] as $k => $docinfo) {
// echo '('.$k.')'.$docinfo["id"]." ";
//.........这里部分代码省略.........
示例8: setGroups
/**
* set group by attr
* 设置分组属性
* @param $group
* $group = array(
* 0=>array("attrname" => "gender","func" => "attr","sort" => "@group desc"),
* );
* @param $distinct
*/
private function setGroups($group, $distinct = '')
{
if (!is_array($group) && empty($group)) {
$this->halt('The argv must be an array and not null.', 1002);
}
$func = array('day' => SPH_GROUPBY_DAY, 'week' => SPH_GROUPBY_WEEK, 'month' => SPH_GROUPBY_MONTH, 'year' => SPH_GROUPBY_YEAR, 'attr' => SPH_GROUPBY_ATTR);
foreach ($group as $k => $v) {
parent::SetGroupBy($v['attrname'], $func[$v['func']], $v['sort']);
}
if ($distinct) {
parent::SetGroupDistinct($distinct);
}
}