本文整理汇总了PHP中SphinxClient::SetGroupBy方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetGroupBy方法的具体用法?PHP SphinxClient::SetGroupBy怎么用?PHP SphinxClient::SetGroupBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetGroupBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyCriteria
protected function applyCriteria(ESphinxCriteria $criteria)
{
$this->applyMatchMode($criteria->matchMode);
$this->applyRankMode($criteria->rankMode);
$this->applySortMode($criteria->sortMode);
// apply select
if (strlen($criteria->select)) {
$this->sphinxClient->SetSelect($criteria->select);
}
// apply limit
if ($criteria->getIsLimited()) {
$this->sphinxClient->SetLimits($criteria->offset, $criteria->limit, $criteria->max_matches, $criteria->cutoff);
}
// apply group
if ($criteria->getIsGroupSetted()) {
$this->sphinxClient->SetGroupBy($criteria->getGroupBy(), $criteria->getGroupFunc());
}
// apply id range
if ($criteria->getIsIdRangeSetted()) {
$this->sphinxClient->SetIDRange($criteria->getIdMin(), $criteria->getIdMax());
}
// apply weights
$this->applyFieldWeights($criteria->getFieldWeights());
$this->applyIndexWeights($criteria->getIndexWeights());
// apply filters
$this->applyFilters($criteria->getInConditions());
$this->applyFilters($criteria->getNotInConditions(), true);
// apply ranges
$this->applyRanges($criteria->getInRanges());
$this->applyRanges($criteria->getNotInRanges(), true);
}
示例2: 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);
}
}
示例3: searchQuery
/**
* This has it's own custom search.
*
* @param mixed[] $search_params
* @param mixed[] $search_words
* @param string[] $excluded_words
* @param int[] $participants
* @param string[] $search_results
*/
public function searchQuery($search_params, $search_words, $excluded_words, &$participants, &$search_results)
{
global $user_info, $context, $modSettings;
// Only request the results if they haven't been cached yet.
if (($cached_results = cache_get_data('search_results_' . md5($user_info['query_see_board'] . '_' . $context['params']))) === null) {
// The API communicating with the search daemon.
require_once SOURCEDIR . '/sphinxapi.php';
// Create an instance of the sphinx client and set a few options.
$mySphinx = new SphinxClient();
$mySphinx->SetServer($modSettings['sphinx_searchd_server'], (int) $modSettings['sphinx_searchd_port']);
$mySphinx->SetLimits(0, (int) $modSettings['sphinx_max_results'], (int) $modSettings['sphinx_max_results']);
// Put together a sort string; besides the main column sort (relevance, id_topic, or num_replies),
$search_params['sort_dir'] = strtoupper($search_params['sort_dir']);
$sphinx_sort = $search_params['sort'] === 'id_msg' ? 'id_topic' : $search_params['sort'];
// Add secondary sorting based on relevance value (if not the main sort method) and age
$sphinx_sort .= ' ' . $search_params['sort_dir'] . ($search_params['sort'] === 'relevance' ? '' : ', relevance DESC') . ', poster_time DESC';
// Include the engines weight values in the group sort
$sphinx_sort = str_replace('relevance ', '@weight ' . $search_params['sort_dir'] . ', relevance ', $sphinx_sort);
// Grouping by topic id makes it return only one result per topic, so don't set that for in-topic searches
if (empty($search_params['topic'])) {
$mySphinx->SetGroupBy('id_topic', SPH_GROUPBY_ATTR, $sphinx_sort);
}
// Set up the sort expresssion
$mySphinx->SetSortMode(SPH_SORT_EXPR, '(@weight + (relevance / 1000))');
// Update the field weights for subject vs body
$mySphinx->SetFieldWeights(array('subject' => !empty($modSettings['search_weight_subject']) ? $modSettings['search_weight_subject'] * 200 : 1000, 'body' => 1000));
// Set the limits based on the search parameters.
if (!empty($search_params['min_msg_id']) || !empty($search_params['max_msg_id'])) {
$mySphinx->SetIDRange($search_params['min_msg_id'], empty($search_params['max_msg_id']) ? (int) $modSettings['maxMsgID'] : $search_params['max_msg_id']);
}
if (!empty($search_params['topic'])) {
$mySphinx->SetFilter('id_topic', array((int) $search_params['topic']));
}
if (!empty($search_params['brd'])) {
$mySphinx->SetFilter('id_board', $search_params['brd']);
}
if (!empty($search_params['memberlist'])) {
$mySphinx->SetFilter('id_member', $search_params['memberlist']);
}
// Construct the (binary mode & |) query while accounting for excluded words
$orResults = array();
$inc_words = array();
foreach ($search_words as $orIndex => $words) {
$inc_words = array_merge($inc_words, $words['indexed_words']);
$andResult = '';
foreach ($words['indexed_words'] as $sphinxWord) {
$andResult .= (in_array($sphinxWord, $excluded_words) ? '-' : '') . $this->_cleanWordSphinx($sphinxWord, $mySphinx) . ' & ';
}
$orResults[] = substr($andResult, 0, -3);
}
// If no search terms are left after comparing against excluded words (i.e. "test -test" or "test last -test -last"),
// sending that to Sphinx would result in a fatal error
if (!count(array_diff($inc_words, $excluded_words))) {
// Instead, fail gracefully (return "no results")
return 0;
}
$query = count($orResults) === 1 ? $orResults[0] : '(' . implode(') | (', $orResults) . ')';
// Subject only searches need to be specified.
if ($search_params['subject_only']) {
$query = '@(subject) ' . $query;
}
// Choose an appropriate matching mode
$mode = SPH_MATCH_ALL;
// Over two words and searching for any (since we build a binary string, this will never get set)
if (substr_count($query, ' ') > 1 && (!empty($search_params['searchtype']) && $search_params['searchtype'] == 2)) {
$mode = SPH_MATCH_ANY;
}
// Binary search?
if (preg_match('~[\\|\\(\\)\\^\\$\\?"\\/=-]~', $query)) {
$mode = SPH_MATCH_EXTENDED;
}
// Set the matching mode
$mySphinx->SetMatchMode($mode);
// Execute the search query.
$request = $mySphinx->Query($query, 'elkarte_index');
// Can a connection to the daemon be made?
if ($request === false) {
// Just log the error.
if ($mySphinx->GetLastError()) {
log_error($mySphinx->GetLastError());
}
fatal_lang_error('error_no_search_daemon');
}
// Get the relevant information from the search results.
$cached_results = array('matches' => array(), 'num_results' => $request['total']);
if (isset($request['matches'])) {
foreach ($request['matches'] as $msgID => $match) {
$cached_results['matches'][$msgID] = array('id' => $match['attrs']['id_topic'], 'relevance' => round($match['attrs']['@count'] + $match['attrs']['relevance'] / 10000, 1) . '%', 'num_matches' => empty($search_params['topic']) ? $match['attrs']['@count'] : 0, 'matches' => array());
}
}
// Store the search results in the cache.
//.........这里部分代码省略.........
示例4: SphinxClient
<?php
require "sphinxapi.php";
$cl = new SphinxClient();
$cl->SetGroupBy('attr', SPH_GROUPBY_ATTR);
$cl->Query('query');
示例5: 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);
//.........这里部分代码省略.........
示例6: searchQuery
public function searchQuery($search_params, $search_words, $excluded_words, &$participants, &$search_results)
{
global $user_info, $context, $sourcedir, $modSettings;
// Only request the results if they haven't been cached yet.
if (($cached_results = cache_get_data('search_results_' . md5($user_info['query_see_board'] . '_' . $context['params']))) === null) {
//!!! Should this not be in here?
// The API communicating with the search daemon.
require_once $sourcedir . '/sphinxapi.php';
// Create an instance of the sphinx client and set a few options.
$mySphinx = new SphinxClient();
$mySphinx->SetServer($modSettings['sphinx_searchd_server'], (int) $modSettings['sphinx_searchd_port']);
$mySphinx->SetLimits(0, (int) $modSettings['sphinx_max_results']);
$mySphinx->SetMatchMode(SPH_MATCH_EXTENDED);
// Put together a sort string; besides the main column sort (relevance, id_topic, or num_replies), add secondary sorting based on relevance value (if not the main sort method) and age
$sphinx_sort = ($search_params['sort'] === 'id_msg' ? 'id_topic' : $search_params['sort']) . ' ' . $search_params['sort_dir'] . ($search_params['sort'] === 'relevance' ? '' : ', relevance desc') . ', poster_time desc';
// Grouping by topic id makes it return only one result per topic, so don't set that for in-topic searches
if (empty($search_params['topic'])) {
$mySphinx->SetGroupBy('id_topic', SPH_GROUPBY_ATTR, $sphinx_sort);
}
$mySphinx->SetSortMode(SPH_SORT_EXTENDED, $sphinx_sort);
// Set the limits based on the search parameters.
if (!empty($search_params['min_msg_id']) || !empty($search_params['max_msg_id'])) {
$mySphinx->SetIDRange($search_params['min_msg_id'], empty($search_params['max_msg_id']) ? (int) $modSettings['maxMsgID'] : $search_params['max_msg_id']);
}
if (!empty($search_params['topic'])) {
$mySphinx->SetFilter('id_topic', array((int) $search_params['topic']));
}
if (!empty($search_params['brd'])) {
$mySphinx->SetFilter('id_board', $search_params['brd']);
}
if (!empty($search_params['memberlist'])) {
$mySphinx->SetFilter('id_member', $search_params['memberlist']);
}
// Construct the (binary mode) query.
$orResults = array();
$inc_words = array();
foreach ($search_words as $orIndex => $words) {
$inc_words = array_merge($inc_words, $words['indexed_words']);
$andResult = '';
foreach ($words['indexed_words'] as $sphinxWord) {
$andResult .= (in_array($sphinxWord, $excluded_words) ? '-' : '') . smc_clean_word_sphinx($sphinxWord, $mySphinx) . ' & ';
}
$orResults[] = substr($andResult, 0, -3);
}
// If no search terms are left after comparing against excluded words (i.e. "test -test" or "test last -test -last"), sending that to Sphinx would result in a fatal error
if (!count(array_diff($inc_words, $excluded_words))) {
// Instead, fail gracefully (return "no results")
return 0;
}
$query = count($orResults) === 1 ? $orResults[0] : '(' . implode(') | (', $orResults) . ')';
// Subject only searches need to be specified.
if ($search_params['subject_only']) {
$query = '@(subject) ' . $query;
}
// Execute the search query.
$request = $mySphinx->Query($query, 'smf_index');
// Can a connection to the daemon be made?
if ($request === false) {
// Just log the error.
if ($mySphinx->GetLastError()) {
log_error($mySphinx->GetLastError());
}
//echo 'error:'.$mySphinx->GetLastError();
fatal_lang_error('error_no_search_daemon');
}
// Get the relevant information from the search results.
$cached_results = array('matches' => array(), 'num_results' => $request['total']);
if (isset($request['matches'])) {
foreach ($request['matches'] as $msgID => $match) {
$cached_results['matches'][$msgID] = array('id' => $match['attrs']['id_topic'], 'relevance' => round($match['attrs']['relevance'] / 10000, 1) . '%', 'num_matches' => empty($search_params['topic']) ? $match['attrs']['@count'] : 0, 'matches' => array());
}
}
// Store the search results in the cache.
cache_put_data('search_results_' . md5($user_info['query_see_board'] . '_' . $context['params']), $cached_results, 600);
}
$participants = array();
foreach (array_slice(array_keys($cached_results['matches']), $_REQUEST['start'], $modSettings['search_results_per_page']) as $msgID) {
$context['topics'][$msgID] = $cached_results['matches'][$msgID];
$participants[$cached_results['matches'][$msgID]['id']] = false;
}
// Sentences need to be broken up in words for proper highlighting.
$search_results = array();
foreach ($search_words as $orIndex => $words) {
$search_results = array_merge($search_results, $search_words[$orIndex]['subject_words']);
}
return $cached_results['num_results'];
}
示例7:
}
}
}
////////////
// 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 > 1000 ? $limit : 1000);
示例8: applyOptions
/**
* Reset sphinx client and apply the options
*
* Only apply filters and group by
*
* @param SearchEngineOptions $options
* @return SphinxSearch
*/
protected function applyOptions(SearchEngineOptions $options)
{
$this->resetSphinx();
$filters = [];
foreach ($options->getCollections() as $collection) {
$filters[] = sprintf("%u", crc32($collection->get_databox()->get_sbas_id() . '_' . $collection->get_coll_id()));
}
$this->sphinx->SetFilter('crc_sbas_coll', $filters);
$this->sphinx->SetFilter('deleted', [0]);
$this->sphinx->SetFilter('parent_record_id', [$options->getSearchType()]);
if ($options->getDateFields() && ($options->getMaxDate() || $options->getMinDate())) {
foreach (array_unique(array_map(function (\databox_field $field) {
return $field->get_name();
}, $options->getDateFields())) as $field) {
$min = $options->getMinDate() ? $options->getMinDate()->format('U') : 0;
$max = $options->getMaxDate() ? $options->getMaxDate()->format('U') : pow(2, 32);
$this->sphinx->SetFilterRange(ConfigurationPanel::DATE_FIELD_PREFIX . $field, $min, $max);
}
}
if ($options->getFields()) {
$filters = [];
foreach ($options->getFields() as $field) {
$filters[] = sprintf("%u", crc32($field->get_databox()->get_sbas_id() . '_' . $field->get_id()));
}
$this->sphinx->SetFilter('crc_struct_id', $filters);
}
if ($options->getBusinessFieldsOn()) {
$crc_coll_business = [];
foreach ($options->getBusinessFieldsOn() as $collection) {
$crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_1'));
$crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_0'));
}
$non_business = [];
foreach ($options->getCollections() as $collection) {
foreach ($options->getBusinessFieldsOn() as $BFcollection) {
if ($collection->get_base_id() == $BFcollection->get_base_id()) {
continue 2;
}
}
$non_business[] = $collection;
}
foreach ($non_business as $collection) {
$crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_0'));
}
$this->sphinx->SetFilter('crc_coll_business', $crc_coll_business);
} elseif ($options->getFields()) {
$this->sphinx->SetFilter('business', [0]);
}
/**
* @todo : enhance : check status in a better way
*/
$status_opts = $options->getStatus();
foreach ($options->getDataboxes() as $databox) {
foreach ($databox->get_statusbits() as $n => $status) {
if (!array_key_exists($n, $status_opts)) {
continue;
}
if (!array_key_exists($databox->get_sbas_id(), $status_opts[$n])) {
continue;
}
$crc = sprintf("%u", crc32($databox->get_sbas_id() . '_' . $n));
$this->sphinx->SetFilter('status', [$crc], $status_opts[$n][$databox->get_sbas_id()] == '0');
}
}
if ($options->getRecordType()) {
$this->sphinx->SetFilter('crc_type', [sprintf("%u", crc32($options->getRecordType()))]);
}
$order = '';
switch ($options->getSortOrder()) {
case SearchEngineOptions::SORT_MODE_ASC:
$order = 'ASC';
break;
case SearchEngineOptions::SORT_MODE_DESC:
default:
$order = 'DESC';
break;
}
switch ($options->getSortBy()) {
case SearchEngineOptions::SORT_RANDOM:
$sort = '@random';
break;
case SearchEngineOptions::SORT_RELEVANCE:
default:
$sort = '@relevance ' . $order . ', created_on ' . $order;
break;
case SearchEngineOptions::SORT_CREATED_ON:
$sort = 'created_on ' . $order;
break;
}
$this->sphinx->SetGroupBy('crc_sbas_record', SPH_GROUPBY_ATTR, $sort);
return $this;
}
示例9:
<?php
phpinfo();
die;
$sphinx = new \SphinxClient();
$sphinx->SetServer('10.80.1.114', 9312);
$sphinx->SetConnectTimeout(1);
$sphinx->SetArrayResult(true);
$sphinx->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$sphinx->setLimits(0, 10, 10000);
$sphinx->setMatchMode(SPH_MATCH_BOOLEAN);
$sphinx->SetSortMode(SPH_SORT_EXTENDED, "sales_volume DESC");
$sphinx->SetFilter('spec_value_id', ['409']);
//$sphinx->setIndexWeights(array(100, 1));
if (isset($param['catArray']) && !empty($param['catArray'])) {
$sphinx->SetFilter('gc_id', $param['catArray']);
}
if (isset($param['styleArray']) && !empty($param['styleArray'])) {
$sphinx->SetFilter('style_id', $param['styleArray']);
}
if (isset($param['brandArray']) && !empty($param['brandArray'])) {
$sphinx->SetFilter('brand_id', $param['brandArray']);
}
$sphinx->SetGroupBy('goods_id', SPH_GROUPBY_ATTR, 'sales_volume DESC');
$res = $sphinx->Query('', 'sku_spec');
echo '<pre>';
var_dump($res);
die;
示例10: 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;
}
示例11: searchQuery
public function searchQuery($search_params, $searchWords, $excludedIndexWords, &$participants, &$searchArray)
{
global $modSettings, $context, $sourcedir, $user_info, $scripturl;
if (($cached_results = CacheAPI::getCache('search_results_' . md5($user_info['query_see_board'] . '_' . $context['params']))) === null) {
require_once $sourcedir . '/contrib/sphinxapi.php';
$mySphinx = new SphinxClient();
$mySphinx->SetServer($modSettings['sphinx_searchd_server'], (int) $modSettings['sphinx_searchd_port']);
$mySphinx->SetLimits(0, (int) $modSettings['sphinx_max_results']);
$mySphinx->SetMatchMode(SPH_MATCH_BOOLEAN);
if (!$search_params['show_complete']) {
$mySphinx->SetGroupBy('ID_TOPIC', SPH_GROUPBY_ATTR);
}
$mySphinx->SetSortMode($search_params['sort_dir'] === 'asc' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, $search_params['sort'] === 'ID_MSG' ? 'ID_TOPIC' : $search_params['sort']);
if (!empty($search_params['topic'])) {
$mySphinx->SetFilter('ID_TOPIC', array((int) $search_params['topic']));
}
if (!empty($search_params['min_msg_id']) || !empty($search_params['max_msg_id'])) {
$mySphinx->SetIDRange(empty($search_params['min_msg_id']) ? 0 : (int) $search_params['min_msg_id'], empty($search_params['max_msg_id']) ? (int) $modSettings['maxMsgID'] : (int) $search_params['max_msg_id']);
}
if (!empty($search_params['brd'])) {
$mySphinx->SetFilter('ID_BOARD', $search_params['brd']);
}
if (!empty($search_params['prefix'])) {
$mySphinx->SetFilter('ID_PREFIX', $search_params['prefix']);
}
if (!empty($search_params['memberlist'])) {
$mySphinx->SetFilter('ID_MEMBER', $search_params['memberlist']);
}
$orResults = array();
foreach ($searchWords as $orIndex => $words) {
$andResult = '';
foreach ($words['indexed_words'] as $sphinxWord) {
$andResult .= (in_array($sphinxWord, $excludedIndexWords) ? '-' : '') . $sphinxWord . ' & ';
}
$orResults[] = substr($andResult, 0, -3);
}
$query = count($orResults) === 1 ? $orResults[0] : '(' . implode(') | (', $orResults) . ')';
// Execute the search query.
$request = $mySphinx->Query($query, 'smf_index');
// Can a connection to the deamon be made?
if ($request === false) {
fatal_lang_error('error_no_search_daemon');
}
// Get the relevant information from the search results.
$cached_results = array('matches' => array(), 'num_results' => $request['total']);
if (isset($request['matches'])) {
foreach ($request['matches'] as $msgID => $match) {
$cached_results['matches'][$msgID] = array('id' => $match['attrs']['id_topic'], 'relevance' => round($match['attrs']['relevance'] / 10000, 1) . '%', 'matches' => array());
if (!$search_params['show_complete']) {
$cached_results['matches'][$msgID]['num_matches'] = $match['attrs']['@count'];
}
}
}
CacheAPI::putCache('search_results_' . md5($user_info['query_see_board']) . '_' . $context['params'], $cached_results, 600);
}
foreach (array_slice(array_keys($cached_results['matches']), $_REQUEST['start'], $modSettings['search_results_per_page']) as $msgID) {
$context['topics'][$msgID] = $cached_results['matches'][$msgID];
$participants[$cached_results['matches'][$msgID]['id']] = false;
}
// Sentences need to be broken up in words for proper highlighting.
foreach ($searchWords as $orIndex => $words) {
$searchArray = array_merge($searchArray, $searchWords[$orIndex]['subject_words']);
}
// Now that we know how many results to expect we can start calculating the page numbers.
$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $cached_results['num_results'], $modSettings['search_results_per_page'], false);
return $cached_results['num_results'];
}
示例12: dataFromSphinx
/**
* 从sphinx获取数据
* @author 吕小虎
* @datetime
* @return
*/
public function dataFromSphinx($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, 1000, 0) as cbweight";
$fieldStr = "id, comname, legal, areaid, uptime,{$gcdweight}";
$sphinx->SetSelect($fieldStr);
//排序 有gccid的靠前
$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->AddQuery('@cate1 ' . $this->data['cate1id'], $indexTable);
$sphinx->SetFilter('cate1', array(intval($this->data['cate1id'])), false);
}
//二级分类筛选
if (!empty($this->data['cate2id']) && intval($this->data['cate2id']) > 0) {
// $sphinx->AddQuery('@cate2 ' . $this->data['cate2id'], $indexTable);
$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'])));
}
}
$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);
$keyStr = '';
//企业名称和企业法人搜索 企业注册号搜索
if (!empty($this->data['wd'])) {
//加快搜索速度
$replace = array('省', '市', '区', '县', '乡', '镇', '有限公司');
$this->data['split'] = str_replace($replace, '', $this->data['split']);
//处理搜索词 提高搜索精度
$keyArr = explode(' ', $this->data['split']);
$keyArr = array_filter($keyArr);
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);
}
}
//cate1
$sphinx->ResetGroupBy();
$sphinx->SetGroupBy('cate1', SPH_GROUPBY_ATTR, "@count desc");
$sphinx->SetLimits(0, 20, 20);
$sphinx->AddQuery('@(comname,legal)' . $keyStr, $indexTable);
//cate2
$sphinx->ResetGroupBy();
$sphinx->SetGroupBy('cate2', SPH_GROUPBY_ATTR, "@count desc");
$sphinx->SetLimits(0, 20, 20);
$sphinx->AddQuery('@(comname,legal)' . $keyStr, $indexTable);
//areaid
$sphinx->ResetGroupBy();
$sphinx->SetGroupBy('areaid', SPH_GROUPBY_ATTR, "@count desc");
$sphinx->SetLimits(0, 20, 20);
$sphinx->AddQuery('@(comname,legal)' . $keyStr, $indexTable);
$result = array();
$batchResult = $sphinx->RunQueries();
$error = $sphinx->getLastError();
if ($error) {
//.........这里部分代码省略.........
示例13: setGroupBy
/**
* Calls SphinxClient::SetGroupBy
* @param $attribute
* @param $func
* @param string $groupsort
*/
public function setGroupBy($attribute, $func, $groupsort = "@group desc")
{
$this->client->SetGroupBy($attribute, $func, $groupsort);
}
示例14: keyword_search
/**
* Performs a search on keywords depending on display specific params. You have to run split_keywords() first
*
* @param string $type contains either posts or topics depending on what should be searched for
* @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
* @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
* @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
* @param string $sort_key is the key of $sort_by_sql for the selected sorting
* @param string $sort_dir is either a or d representing ASC and DESC
* @param string $sort_days specifies the maximum amount of days a post may be old
* @param array $ex_fid_ary specifies an array of forum ids which should not be searched
* @param string $post_visibility specifies which types of posts the user can view in which forums
* @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
* @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
* @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
* @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
* @param int $start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results
*/
public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
{
global $user, $phpbb_log;
// No keywords? No posts.
if (!strlen($this->search_query) && !sizeof($author_ary)) {
return false;
}
$id_ary = array();
// Sorting
if ($type == 'topics') {
switch ($sort_key) {
case 'a':
$this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'poster_id ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
break;
case 'f':
$this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'forum_id ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
break;
case 'i':
case 's':
$this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'post_subject ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
break;
case 't':
default:
$this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'topic_last_post_time ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
break;
}
} else {
switch ($sort_key) {
case 'a':
$this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'poster_id');
break;
case 'f':
$this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'forum_id');
break;
case 'i':
case 's':
$this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_subject');
break;
case 't':
default:
$this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_time');
break;
}
}
// Most narrow filters first
if ($topic_id) {
$this->sphinx->SetFilter('topic_id', array($topic_id));
}
/**
* Allow modifying the Sphinx search options
*
* @event core.search_sphinx_keywords_modify_options
* @var string type Searching type ('posts', 'topics')
* @var string fields Searching fields ('titleonly', 'msgonly', 'firstpost', 'all')
* @var string terms Searching terms ('all', 'any')
* @var int sort_days Time, in days, of the oldest possible post to list
* @var string sort_key The sort type used from the possible sort types
* @var int topic_id Limit the search to this topic_id only
* @var array ex_fid_ary Which forums not to search on
* @var string post_visibility Post visibility data
* @var array author_ary Array of user_id containing the users to filter the results to
* @var string author_name The username to search on
* @var object sphinx The Sphinx searchd client object
* @since 3.1.7-RC1
*/
$sphinx = $this->sphinx;
$vars = array('type', 'fields', 'terms', 'sort_days', 'sort_key', 'topic_id', 'ex_fid_ary', 'post_visibility', 'author_ary', 'author_name', 'sphinx');
extract($this->phpbb_dispatcher->trigger_event('core.search_sphinx_keywords_modify_options', compact($vars)));
$this->sphinx = $sphinx;
unset($sphinx);
$search_query_prefix = '';
switch ($fields) {
case 'titleonly':
// Only search the title
if ($terms == 'all') {
$search_query_prefix = '@title ';
}
// Weight for the title
$this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
// 1 is first_post, 0 is not first post
//.........这里部分代码省略.........
示例15: 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);
//.........这里部分代码省略.........