本文整理汇总了PHP中SphinxClient::SetSortMode方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetSortMode方法的具体用法?PHP SphinxClient::SetSortMode怎么用?PHP SphinxClient::SetSortMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetSortMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: InitSphinx
/**
* Инициализация сфинкса
*/
protected function InitSphinx()
{
/**
* Получаем объект Сфинкса(из Сфинкс АПИ)
*/
$this->oSphinx = new SphinxClient();
$this->oSphinx->SetServer(Config::Get('module.search.sphinx.host'), intval(Config::Get('module.search.sphinx.port')));
/**
* Устанавливаем тип сортировки
*/
$this->oSphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC, @id DESc");
}
示例2: get_sugg_trigrams
private function get_sugg_trigrams($word, SearchEngineOptions $options)
{
$trigrams = $this->BuildTrigrams($word);
$query = "\"{$trigrams}\"/1";
$len = strlen($word);
$this->resetSphinx();
$this->suggestionClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$this->suggestionClient->SetRankingMode(SPH_RANK_WORDCOUNT);
$this->suggestionClient->SetFilterRange("len", $len - 2, $len + 4);
$this->suggestionClient->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
$this->suggestionClient->SetLimits(0, 10);
$indexes = [];
foreach ($options->getDataboxes() as $databox) {
$indexes[] = 'suggest' . $this->CRCdatabox($databox);
}
$index = implode(',', $indexes);
$res = $this->suggestionClient->Query($query, $index);
if ($this->suggestionClient->Status() === false) {
return [];
}
if (!$res || !isset($res["matches"])) {
return [];
}
$words = [];
foreach ($res["matches"] as $match) {
$words[] = $match['attrs']['keyword'];
}
return $words;
}
示例3: searchTasks
/**
*
* @param string $query
* @return array of integers - taskIds
*/
public static function searchTasks($query)
{
$fieldWeights = array('description' => 10, 'note' => 6);
$indexName = 'plancake_tasks';
$client = new SphinxClient();
// $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port'));
$client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId()));
$client->SetConnectTimeout(1);
$client->SetMatchMode(SPH_MATCH_ANY);
$client->SetSortMode(SPH_SORT_RELEVANCE);
$client->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$client->SetArrayResult(true);
$client->SetFieldWeights($fieldWeights);
$client->setLimits(0, 100);
$results = $client->query($client->EscapeString($query), $indexName);
if ($results === false) {
$error = "Sphinx Error - " . $client->GetLastError();
sfErrorNotifier::alert($error);
}
$ids = array();
if (isset($results['matches']) && count($results['matches'])) {
foreach ($results['matches'] as $match) {
$ids[] = $match['id'];
}
}
return PcTaskPeer::retrieveByPKs($ids);
}
示例4: query
function query($query, $index, $offset = 0)
{
require_once DIR . "lib/sphinx/sphinxapi.php";
$sphinx = new SphinxClient();
$sphinx->setServer(SPHINX_HOST, SPHINX_PORT);
$sphinx->SetLimits($offset, 100, 10000000);
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
$sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'date_posted');
$res = $sphinx->Query($query, $index);
return $res;
}
示例5: InitSphinx
/**
* Инициализация сфинкса
*/
protected function InitSphinx()
{
// * Получаем объект Сфинкса(из Сфинкс АПИ)
$this->oSphinx = new SphinxClient();
$sHost = Config::Get('plugin.sphinx.host');
$nPort = 0;
if (strpos($sHost, ':')) {
list($sHost, $nPort) = explode(':', $sHost);
}
// * Подключаемся
$this->oSphinx->SetServer($sHost, intval($nPort));
$sError = $this->GetLastError();
if ($sError) {
$sError .= "\nhost:{$sHost}";
$this->LogError($sError);
return false;
}
// * Устанавливаем тип сортировки
$this->oSphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC, @id DESc");
}
示例6: get_list
/**
* 获取竞品信息
* @author zhangxiao@dachuwang.com
*/
public function get_list($friend_id = null, $city_id = null, $key, $key_word = null, $cate_name = null, $offset = 0, $page_size = 10)
{
$key = $key ?: $this->input->get_post('search_key', TRUE);
$key_word = $key_word ?: $this->input->get_post('search_value', TRUE);
$cate_name = $cate_name ?: $this->input->get_post('cate_name', TRUE);
$friend_id = $friend_id ?: $this->input->get_post('friend_id', TRUE);
$city_id = $city_id ?: $this->input->get_post('city_id', TRUE);
//使用sphinx
$s = new SphinxClient();
$s->setServer(C('service.spider'), 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->setLimits($offset, $page_size, 100000);
$s->setMaxQueryTime(30);
//筛选友商城市
if ($city_id != C('open_cities.quanguo.id')) {
$s->setFilter('city_id', array($city_id));
}
//筛选友商站点
if ($friend_id != C('anti_sites.all.id')) {
$s->setFilter('site_id', array($friend_id));
}
$s->SetSortMode(SPH_SORT_EXTENDED, "product_id asc");
$fields = '';
//筛选关键字
if ($key_word) {
if ($key == 'product_name') {
$fields .= '@title "' . $key_word . '" ';
} elseif ($key == 'product_id') {
$s->setFilter('product_id', array($key_word));
} elseif ($key == 'sku_number') {
$auto_ids = $this->_get_product_by_sku_num($key_word);
if ($auto_ids) {
$s->setFilter('auto_id', $auto_ids);
} else {
return array('total' => 0, 'data' => []);
}
}
}
//筛选友商品类名称
if ($cate_name) {
$fields .= '@category_name "' . $cate_name . '" ';
}
$result = $s->query($fields, 'anti_products');
if (isset($result['matches'])) {
$list = array_column($result['matches'], 'attrs');
} else {
$list = array();
}
$final_list = $this->_assemble_sku_num($list);
$return = array('total' => $result['total'], 'data' => $final_list);
return $return;
}
示例7: institutions
private function institutions($data)
{
$q = $this->getRequestParameter("q", '');
if (!$q) {
throw new BadRequestException('A search string must be provided.');
}
$page = $this->getRequestParameter("page", '1');
$limit = $this->getRequestParameter("limit", self::PAGE_SIZE);
$culture = $this->getRequestParameter("culture", 'es');
$type = $this->getRequestParameter("type", false);
$this->getUser()->setCulture($culture);
$cl = new SphinxClient();
$dbConf = Propel::getConfiguration();
$dsn = $dbConf['datasources']['propel']['connection']['dsn'];
$sphinxServer = sfConfig::get('sf_sphinx_server');
$cl->SetServer($sphinxServer, 3312);
$this->limit = 1000;
$cl->SetLimits(0, $this->limit, $this->limit);
$cl->SetArrayResult(true);
#instituciones
$this->res = $cl->Query($q, "institucion_{$culture}");
$cl->SetFieldWeights(array('vanity' => 5));
$cl->SetSortMode(SPH_SORT_RELEVANCE);
$institutions = array();
if ($this->res !== false) {
if (isset($this->res["matches"]) && is_array($this->res["matches"])) {
$c = new Criteria();
$list = array();
foreach ($this->res["matches"] as $idx => $match) {
$list[] = $match['id'];
}
$c->add(InstitucionPeer::ID, $list, Criteria::IN);
$c->addAscendingOrderByColumn(InstitucionPeer::ORDEN);
//$instituciones = InstitucionPeer::doSelect($c);
$pager = new sfPropelPager('Institucion', $limit);
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter('page', $page));
$pager->init();
foreach ($pager->getResults() as $aInstitution) {
$institution = new Institution();
$institution->setId($aInstitution->getId());
$institution->setVanity($aInstitution->getVanity());
$institution->setName($aInstitution->getNombreCorto());
$institution->setLongName($aInstitution->getNombre());
$institutions[] = $institution;
}
}
}
return $institutions;
}
示例8: 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("*");
}
示例9: 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;
}
示例10: getResultByTag
public function getResultByTag($keyword = "", $offset = 0, $limit = 0, $searchParams = array())
{
$sphinx = $this->config->item('sphinx');
$query = array();
$cl = new SphinxClient();
$cl->SetServer($sphinx['ip'], $sphinx['port']);
// 注意这里的主机
$cl->SetConnectTimeout($sphinx['timeout']);
$cl->SetArrayResult(true);
// $cl->SetIDRange(89,90);//过滤ID
if (isset($searchParams['provice_sid']) && $searchParams['provice_sid']) {
$cl->setFilter('provice_sid', array($searchParams['provice_sid']));
}
if (isset($searchParams['city_sid']) && $searchParams['city_sid']) {
$cl->setFilter('city_sid', array($searchParams['city_sid']));
}
if (isset($searchParams['piccode']) && $searchParams['piccode']) {
$cl->setFilter('piccode', array($searchParams['piccode']));
}
if (isset($searchParams['recent']) && $searchParams['recent']) {
$cl->SetFilterRange('createtime', time() - 86400 * 30, time());
//近期1个月
}
if (isset($searchParams['searchtype']) && $searchParams['searchtype']) {
//精确:模糊
$searchtype = SPH_MATCH_ALL;
} else {
$searchtype = SPH_MATCH_ANY;
}
$cl->SetLimits($offset, $limit);
$cl->SetMatchMode($searchtype);
// 使用多字段模式
$cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc,@id desc");
$index = "*";
$query = $cl->Query($keyword, $index);
$cl->close();
return $query;
}
示例11: elseif
$mode = SPH_MATCH_ALL;
if (strpos($q, '~') === 0) {
$q = preg_replace('/^\\~/', '', $q);
if (substr_count($q, ' ') > 1) {
//over 2 words
$mode = SPH_MATCH_ANY;
}
} elseif (strpos($q, '-') !== FALSE || strpos($q, '|') !== FALSE) {
$mode = SPH_MATCH_EXTENDED;
}
$index = "gaz";
$cl = new SphinxClient();
$cl->SetServer($CONF['sphinx_host'], $CONF['sphinx_port']);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
$cl->SetSortMode(SPH_SORT_EXTENDED, "score ASC, @relevance DESC");
$cl->SetLimits(0, 20);
$res = $cl->Query($q, $index);
// --------------
if (!empty($_GET['debug'])) {
print_r($res);
}
if ($res === false) {
print "\tQuery failed: -- please try again later.\n";
exit;
} else {
if ($cl->GetLastWarning()) {
print "\nWARNING: " . $cl->GetLastWarning() . "\n\n";
}
$query_info = "Query '{$q}' retrieved " . count($res['matches']) . " of {$res['total_found']} matches in {$res['time']} sec.\n";
}
示例12: array
function draw2()
{
$keywords = AZLib::getParam('keywords');
$total_item = 0;
$search_result = false;
$items = array();
$paging = '';
$cmd = '';
$cat_search_id = 0;
$item_array = array();
$listCat = array();
if ($keywords) {
//AZLib::getCats();
require "./includes/sphinxapi.class.php";
foreach (CGlobal::$allCategories as $value) {
if ($value['parent_id'] == 0) {
$cat_list[$value['id']] = $value['brief_name'];
}
}
$category = $this->getTotalPerCategory($keywords);
foreach ($category as $row) {
$row['brief_name'] = isset($cat_list[$row['level_1_catid']]) && $cat_list[$row['level_1_catid']] ? $cat_list[$row['level_1_catid']] : "Khác";
$listCat[$row['level_1_catid']] = array("level_1_catid" => $row["level_1_catid"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
}
$total = 0;
$catid = 0;
$catActive = '';
$total_cat = 0;
if ($listCat) {
$first_val = array_slice($listCat, 0, 1);
$total = $first_val[0]['count_ad'];
$catid = $first_val[0]['level_1_catid'];
$catActive = $first_val[0]['brief_name'];
$total_cat = count($listCat);
}
$i = 0;
$allrecord = 0;
$otherCat = '';
$cat_content = "";
foreach ($listCat as $cat) {
if ($i < 3) {
$active = $i == 0 ? "class=\"active\"" : "";
$cat_content .= "<li id=\"tab_{$i}\" {$active} onclick=\"javascript:acive_tab_cat(this);\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></li>";
} else {
$otherCat .= "<div class=\"other\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);acive_tab_cat(this);\" id=\"tab_{$i}\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></div>";
}
$i++;
$allrecord = $allrecord + $cat['count_ad'];
}
$display->add("cat_content", $cat_content);
$display->add("CatActiveId", $catid);
$display->add("catActive", $catActive);
$display->add("listCat", $listCat);
$display->add("allrecord", $allrecord);
$display->add("otherCat", str_replace(array(chr(13), chr(10)), "", $otherCat));
$display->add("total_cat", $total_cat);
//Init for sphinx search paging
$pager = new Pager();
//config
$limit = SEARCH_LIMIT;
$pager->type = "search";
$pager->catid = $catid;
$pager->total = $total;
$pager->limit = $limit;
$pager->page_param = 'page';
$pager->page = 1;
$offset = $pager->get_offset();
$limit_from = $pager->limit_from();
$limit_to = $pager->limit_to();
//Sphinx search by Nova
$q = $keywords;
$mode = SPH_MATCH_EXTENDED2;
//Init config
$host = SPHINX_SERVER;
$port = SPHINX_PORT;
//$index = SPHINX_INDEX;
$index = "enbac delta";
$filtervals = array();
$ranker = SPH_RANK_WORDCOUNT;
$cl = new SphinxClient();
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
//filter
if ($catid) {
$cl->SetFilter('level_1_catid', array($catid));
}
$cl->SetFilter('status', array('1'));
$cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
//$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
//$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
//$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
$cl->SetSortMode(SPH_SORT_EXPR, "@weight");
//Sort theo trọng số
//SPH_RANK_WORDCOUNT
//SPH_MATCH_EXTENDED2
//end filter
$cl->SetLimits($offset, $limit, 10000);
$cl->SetRankingMode($ranker);
//.........这里部分代码省略.........
示例13: index
public function index()
{
C('TOKEN_ON', false);
$seo = seo();
$this->assign("seo", $seo);
if (isset($_GET['q'])) {
G('search');
//关键字
$q = Input::forSearch(safe_replace($this->_get("q")));
$q = htmlspecialchars(strip_tags($q));
//时间范围
$time = $this->_get("time");
//模型
$mid = (int) $this->_get("modelid");
//栏目
$catid = (int) $this->_get("catid");
//排序
$order = array("adddate" => "DESC", "searchid" => "DESC");
//搜索历史记录
$shistory = cookie("shistory");
if (!$shistory) {
$shistory = array();
}
$model = F("Model");
$category = F("Category");
if (trim($_GET['q']) == '') {
header('Location: ' . U("Search/Index/index"));
exit;
}
array_unshift($shistory, $q);
$shistory = array_slice(array_unique($shistory), 0, 10);
//加入搜索历史
cookie("shistory", $shistory);
$where = array();
//每页显示条数
$pagesize = $this->config['pagesize'] ? $this->config['pagesize'] : 10;
//缓存时间
$cachetime = (int) $this->config['cachetime'];
//按时间搜索
if ($time == 'day') {
//一天
$search_time = time() - 86400;
$where['adddate'] = array("GT", $search_time);
} elseif ($time == 'week') {
//一周
$search_time = time() - 604800;
$where['adddate'] = array("GT", $search_time);
} elseif ($time == 'month') {
//一月
$search_time = time() - 2592000;
$where['adddate'] = array("GT", $search_time);
} elseif ($time == 'year') {
//一年
$search_time = time() - 31536000;
$where['adddate'] = array("GT", $search_time);
} else {
$search_time = 0;
}
//可用数据源
$this->config['modelid'] = $this->config['modelid'] ? $this->config['modelid'] : array();
//按模型搜索
if ($mid && in_array($mid, $this->config['modelid'])) {
$where['modelid'] = array("EQ", (int) $mid);
}
//按栏目搜索
if ($catid) {
//不支持多栏目搜索,和父栏目搜索。
$where['catid'] = array("EQ", (int) $catid);
}
//分页模板
$TP = '共有{recordcount}条信息 {pageindex}/{pagecount} {first}{prev}{liststart}{list}{listend}{next}{last}';
//如果开启sphinx
if ($this->config['sphinxenable']) {
import("Sphinxapi", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
$sphinxhost = $this->config['sphinxhost'];
$sphinxport = $this->config['sphinxport'];
$cl = new SphinxClient();
//设置searchd的主机名和TCP端口
$cl->SetServer($sphinxhost, $sphinxport);
//设置连接超时
$cl->SetConnectTimeout(1);
//控制搜索结果集的返回格式
$cl->SetArrayResult(true);
//设置全文查询的匹配模式 api http://docs.php.net/manual/zh/sphinxclient.setmatchmode.php
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
//设置排名模式 api http://docs.php.net/manual/zh/sphinxclient.setrankingmode.php
$cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
//按一种类似SQL的方式将列组合起来,升序或降序排列。用weight是权重排序
$cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc");
//设置返回结果集偏移量和数目
$page = (int) $this->_get(C("VAR_PAGE"));
$page = $page < 1 ? 1 : $page;
$offset = $pagesize * ($page - 1);
$cl->SetLimits($offset, $pagesize, $pagesize > 1000 ? $pagesize : 1000);
if (in_array($time, array("day", "week", "month", "year"))) {
//过滤时间
$cl->SetFilterRange('adddate', $search_time, time(), false);
}
if ($mid && in_array($mid, $this->config['modelid'])) {
//过滤模型
//.........这里部分代码省略.........
示例14: SphinxClient
<?php
require "sphinxapi.php";
$cl = new SphinxClient();
$cl->SetSortMode(SPH_SORT_ATTR_ASC, 'sortby');
$cl->Query('query');
示例15: search
function search()
{
global $display;
$catid = (int) Url::get('catid', 0);
$total = (int) Url::get('total', 0);
$page = (int) Url::get('page', 0);
$tt = (int) Url::get('tt', 0);
$keywords = Url::get('keywords');
require "./includes/sphinxapi.class.php";
EClassApi::getCats();
foreach (CGlobal::$allCategories as $value) {
if ($value['parent_id'] == 0) {
$cat_list[$value['id']] = $value['brief_name'];
}
}
$category = $this->getCategory($keywords);
foreach ($category as $row) {
$row['brief_name'] = isset($cat_list[$row['level_1_category_id']]) && $cat_list[$row['level_1_category_id']] ? $cat_list[$row['level_1_category_id']] : "Khác";
$listCat[$row['level_1_category_id']] = array("level_1_category_id" => $row["level_1_category_id"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
}
$catActive = '';
$total_cat = 0;
if ($listCat) {
$catActive = $listCat[$catid]['brief_name'];
$total_cat = count($listCat);
}
$i = 0;
$allrecord = 0;
$otherCat = '';
$cat_content = "";
foreach ($listCat as $cat) {
$allrecord = $allrecord + $cat['count_ad'];
}
$display->add("cat_content", $cat_content);
$display->add("CatActiveId", $catid);
$display->add("catActive", $catActive);
$display->add("listCat", $listCat);
$display->add("allrecord", $allrecord);
$display->add("total_cat", $total_cat);
$pager = new Pager();
$limit = SEARCH_LIMIT;
$pager->type = "search";
$pager->catid = $catid;
$pager->total = $total;
$pager->limit = $limit;
$pager->page_param = 'page';
$pager->page = $page;
$offset = $pager->get_offset();
$limit_from = $pager->limit_from();
$limit_to = $pager->limit_to();
//Sphinx search by Nova
$q = $keywords;
//$mode = SPH_MATCH_ALL;
$mode = SPH_MATCH_EXTENDED2;
//Init config
$host = SPHINX_SERVER;
$port = SPHINX_PORT;
$index = 'enbac';
$filtervals = array();
//$ranker = SPH_RANK_PROXIMITY_BM25;
$ranker = SPH_RANK_WORDCOUNT;
$cl = new SphinxClient();
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
$cl->SetFilter('level_1_category_id', array($catid));
$cl->SetFilter('status', array('1'));
$cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
//$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
//$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
//$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
$cl->SetSortMode(SPH_SORT_EXPR, "@weight");
//Sort theo trọng số
$cl->SetLimits($offset, $limit, 10000);
$cl->SetRankingMode($ranker);
$cl->SetArrayResult(true);
$res = $cl->Query($q, $index);
if ($res && isset($res["matches"])) {
if (is_array($res["matches"])) {
foreach ($res["matches"] as $results) {
$list_item_id[] = $results['id'];
}
}
$comma_separated = join(",", $list_item_id);
}
if ($total) {
if ($limit_to > $total) {
$limit_to = $total;
}
$comma_separated = join(",", $list_item_id);
if ($comma_separated) {
//$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ($comma_separated) AND status=1 ORDER BY up_time DESC";
$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
$search_result = DB::query($sql);
$pager->total = $total;
$paging = $pager->page_link();
}
}
$item_array = array();
//.........这里部分代码省略.........