本文整理汇总了PHP中SphinxClient::setMatchMode方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::setMatchMode方法的具体用法?PHP SphinxClient::setMatchMode怎么用?PHP SphinxClient::setMatchMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::setMatchMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
parent::__construct();
// 获取关键字
$this->keyword = t($this->data['keyword']);
$this->type = $this->data['type'] ? intval($this->data['type']) : 1;
// 分页数
$page = intval($this->data['page']);
$page <= 0 && ($page = 1);
// 分页大小
$pageSize = 10;
// 使用sphinx进行搜索功能
$sphinx = new SphinxClient();
// 配置sphinx服务器信息
$sphinx->SetServer(self::SPHINX_HOST, self::SPHINX_PORT);
// 配置返回结果集
$sphinx->SetArrayResult(true);
// 匹配结果偏移量
$sphinx->SetLimits(($page - 1) * $pageSize, $pageSize, 1000);
// 设置最大搜索时间
$sphinx->SetMaxQueryTime(3);
// 设置搜索模式
$sphinx->setMatchMode(SPH_MATCH_PHRASE);
$this->sphinx = $sphinx;
}
示例2: newSphinxClient
public static function newSphinxClient()
{
$s = new SphinxClient();
$s->setServer(Yii::app()->params['sphinx_servername'], Yii::app()->params['sphinx_port']);
$s->setMaxQueryTime(10000);
$s->setLimits(0, 5000, 5000);
$s->setMatchMode(SPH_MATCH_EXTENDED);
return $s;
}
示例3: 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;
}
示例4: while
while ($member = DB::fetch($query)) {
$uids[] = $member['uid'];
}
if (count($uids) == 0) {
$uids = array(0);
}
} elseif ($srchuid) {
$uids = array($srchuid);
}
if (is_array($uids) && count($uids) > 0) {
$s->setFilter('authorid', $uids, false);
}
if ($srchtxt) {
if (preg_match("/\".*\"/", $srchtxt)) {
$spx_matchmode = "PHRASE";
$s->setMatchMode(SPH_MATCH_PHRASE);
} elseif (preg_match("(AND|\\+|&|\\s)", $srchtxt) && !preg_match("(OR|\\|)", $srchtxt)) {
$srchtxt = preg_replace("/( AND |&| )/is", "+", $srchtxt);
$spx_matchmode = "ALL";
$s->setMatchMode(SPH_MATCH_ALL);
} else {
$srchtxt = preg_replace("/( OR |\\|)/is", "+", $srchtxt);
$spx_matchmode = 'ANY';
$s->setMatchMode(SPH_MATCH_ANY);
}
$srchtxt = str_replace('*', '%', addcslashes($srchtxt, '%_'));
foreach (explode('+', $srchtxt) as $text) {
$text = trim($text);
if ($text) {
$sqltxtsrch .= $andor;
$sqltxtsrch .= $srchtype == 'fulltext' ? "(p.message LIKE '%" . str_replace('_', '\\_', $text) . "%' OR p.subject LIKE '%{$text}%')" : "t.subject LIKE '%{$text}%'";
示例5: fetch
public function fetch()
{
if (!class_exists('SphinxClient')) {
return false;
}
$s = new SphinxClient();
$s->setServer($this->_sphinxHost, $this->_sphinxPort);
if (count($this->_arrSearchOutRangeColumnMinMax) > 0) {
foreach ($this->_arrSearchOutRangeColumnMinMax as $value) {
$d = explode(',', $value);
$s->setFilterRange($d[0], $d[1], $d[2], true);
}
}
if (count($this->_arrSearchInRangeColumnMinMax) > 0) {
foreach ($this->_arrSearchInRangeColumnMinMax as $value) {
$d = explode(',', $value);
$s->setFilterRange($d[0], $d[1], $d[2], false);
}
}
$s->setConnectTimeout($this->_connectTimeout);
$s->setMaxQueryTime($this->{$_maxquerytime});
// $s->setRetries ( int $this->retriesCount , int $this->retriesDelay );
//
$s->setMatchMode($this->searchMode);
$s->setFieldWeights($this->_fieldweights);
// $s->setFilter ( string $attribute , array $values [, bool $exclude = false ] );
// $s->setFilterFloatRange ( string $attribute , float $min , float $max [, bool $exclude = false ] );
// $s->setFilterRange ( string $attribute , int $min , int $max [, bool $exclude = false ] );
// $s->setGeoAnchor ( string $attrlat , string $attrlong , float $latitude , float $longitude );
// $s->setGroupBy ( string $attribute , int $func [, string $groupsort = "@group desc" ] );
// $s->setGroupDistinct ( string $attribute );
// $s->setIDRange ( int $min , int $max );
$s->setIndexWeights($this->_arrIndexweights);
// $s->setLimits ( int $offset , int $limit [, int $max_matches = 0 [, int $cutoff = 0 ]] );
$s->setMatchMode($this->searchMode);
// $s->setOverride ( string $attribute , int $type , array $values );
$s->setRankingMode($this->rankMode);
// $s->setSelect ( string $clause );
// $s->setSortMode ( int $mode [, string $sortby ] );
return $s->query($this->_query);
}
示例6: search
public function search(Request $request)
{
//$keyword = '服务器';
//$keywords = $requests->get('keywords');
//$requests = $request;
//return $requests->get('keywords')->toString();
$keyword = $request->get('keywords');
//$keyword = $keywords ? addslashes($keywords) : addslashes($_REQUEST['keywords']);
//header("content-type:text/html;charset=utf-8");
// include('/home/tmp/tool/coreseek-3.2.14/csft-3.2.14/api/sphinxapi.php');
$s = new \SphinxClient();
$s->setServer("localhost", 9312);
$s->setArrayResult(true);
// $s->setSelect();
$s->setMatchMode(SPH_MATCH_ALL);
$result = $searchList = array();
if ($keyword) {
$result = $s->query($keyword, 'test1');
// 获取检索到的文章id
$idArr = array();
$data = $titleArr = array();
if (isset($result['matches']) && is_array($result['matches'])) {
foreach ($result['matches'] as $k => $v) {
$idArr[] = $v['attrs']['article_id'];
}
$idStr = implode(',', $idArr);
// 查找文章
$data['articles'] = \DB::table('blog_articles')->whereRaw('id in (' . $idStr . ')')->get();
$contentArr = \DB::table('blog_content')->whereRaw('article_id in (' . $idStr . ')')->get();
if ($contentArr) {
$newContentArr = array();
foreach ($contentArr as $k => $v) {
$newContentArr[$v->article_id] = $v->content;
}
$contentArr = $newContentArr;
unset($newContentArr);
}
if ($data['articles']) {
foreach ($data['articles'] as $k => $v) {
$searchList[$k]['id'] = $v->id;
$searchList[$k]['title'] = $v->title;
$searchList[$k]['content'] = $contentArr[$v->id];
}
}
//var_dump($searchList);exit();
return view('articles.search', compact('searchList'));
}
} else {
$searchList[0]['message'] = '请输入要查询的关键词~';
return;
}
return view('articles.search', compact('searchList'));
//var_dump(rand(1000,9999));
//return '';
}
示例7: getSphinx
private static function getSphinx()
{
// {{{
$sphinx = new SphinxClient();
$sphinx->setServer("localhost", 9312);
$sphinx->setMatchMode(SphinxClient::SPH_MATCH_PHRASE);
$sphinx->setLimits(0, 1000);
$sphinx->setMaxQueryTime(30);
return $sphinx;
}
示例8: getSphinxResults
/**
* Method to fetch all Sphinx results for a certain search phrase
*
* @param string $text The search phrase
* @param string $phrase String how to match the phrase
* @param string $ordering String describing the ordering
*
* @return array
*/
protected function getSphinxResults($text, $phrase = '', $ordering = '')
{
$host = $this->params->get('host', 'localhost');
$port = $this->params->get('port', 9312);
$index = $this->params->get('index');
switch ($phrase) {
case 'exact':
$matchMode = SPH_MATCH_PHRASE;
break;
case 'all':
$matchMode = SPH_MATCH_ALL;
break;
case 'any':
default:
$matchMode = SPH_MATCH_ANY;
break;
}
$s = new SphinxClient();
$s->setServer($host, $port);
$s->setMatchMode($matchMode);
$s->setLimits(50);
$result = $s->query($text, $index);
return $result;
}
示例9: getSphinxSearchedResult
/**
* @brief 위치 기반 Sphinx 검색 부분 (외부/내부 호출용..)
* @param $document_srl 문서 번호
* @param $lat 위도
* @param $lon 경도
* @return 검색된 결과 리스트
*/
function getSphinxSearchedResult($document_srl, $lat, $lon)
{
$s = new SphinxClient();
$oModuleModel =& getModel('module');
$config = $oModuleModel->getModuleConfig('aroundmap');
$s->setServer($config->serverName, $config->serverPort);
$s->setLimits(0, 10);
$s->setMatchMode(SPH_MATCH_ALL);
$s->SetSortMode(SPH_SORT_EXTENDED, '@geodist ASC');
$s->setFilter("document_srl", array($document_srl), true);
$s->SetFilterFloatRange("@geodist", 0, 10000);
$s->setMaxQueryTime(3);
$s->setGeoAnchor("lat", "lon", (double) deg2rad($lat), (double) deg2rad($lon));
$result = $s->query("", "idx_aroundmap");
$ret = array();
if ($result[total_found] > 0) {
$ret = $result[matches];
}
return $ret;
}
示例10: full_search
/**
* 全文搜索
*
*/
protected function full_search($search_txt, $type)
{
$conf = C('fullindexer');
$cl = new SphinxClient();
$cl->SetServer($conf['host'], $conf['port']);
$cl->SetConnectTimeout(1);
$cl->SetArrayResult(true);
$cl->SetRankingMode($conf['rankingmode'] ? $conf['rankingmode'] : 0);
$cl->setLimits(0, $conf['querylimit']);
$matchmode = $conf['matchmode'];
$cl->setMatchMode($matchmode);
$res = $cl->Query($search_txt, $conf[$type]);
if ($res) {
if (is_array($res['matches'])) {
foreach ($res['matches'] as $value) {
$matchs_id[] = $value['id'];
}
}
}
return is_array($matchs_id) ? implode(',', $matchs_id) : '';
}
示例11:
<?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;
示例12: actionSearch
/**
* Provides search functionality through Sphinx
* @param int $id The pagination $id
*/
public function actionSearch($id = 1)
{
$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array('{{app_name}}' => Cii::getConfig('name', Yii::app()->name), '{{label}}' => Yii::t('ciims.controllers.Site', 'Search'))));
$this->layout = '//layouts/default';
$data = array();
$pages = array();
$itemCount = 0;
$pageSize = Cii::getConfig('searchPaginationSize', 10);
if (Cii::get($_GET, 'q', "") != "") {
$criteria = Content::model()->getBaseCriteria();
if (strpos($_GET['q'], 'user_id') !== false) {
$criteria->addCondition('author_id = :author_id');
$criteria->params = array(':author_id' => str_replace('user_id:', '', $_GET['q']));
} else {
// Load the search data
Yii::import('ext.sphinx.SphinxClient');
$sphinx = new SphinxClient();
$sphinx->setServer(Cii::getConfig('sphinxHost'), (int) Cii::getConfig('sphinxPort'));
$sphinx->setMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->setMaxQueryTime(15);
$result = $sphinx->query(Cii::get($_GET, 'q', NULL), Cii::getConfig('sphinxSource'));
$criteria->addInCondition('id', array_keys(isset($result['matches']) ? $result['matches'] : array()));
}
$criteria->addCondition('password = ""');
$criteria->limit = $pageSize;
$criteria->order = 'id DESC';
$itemCount = Content::model()->count($criteria);
$pages = new CPagination($itemCount);
$pages->pageSize = $pageSize;
$criteria->offset = $criteria->limit * $pages->getCurrentPage();
$data = Content::model()->findAll($criteria);
$pages->applyLimit($criteria);
}
$this->render('search', array('url' => 'search', 'id' => $id, 'data' => $data, 'itemCount' => $itemCount, 'pages' => $pages));
}
示例13: search_posts
/**
* Runs a search against sphinx
*
* @param array $args
* @return array Sphinx result set
*/
public function search_posts($args)
{
$options = $this->get_options();
$defaults = array('search_using' => 'any', 'sort' => 'match', 'paged' => 1, 'posts_per_page' => 0, 'showposts' => 0);
$args = wp_parse_args($args, $defaults);
$sphinx = new SphinxClient();
$sphinx->setServer($options['server'], $options['port']);
$search = $args['s'];
switch ($args['search_using']) {
case 'all':
$sphinx->setMatchMode(SPH_MATCH_ALL);
break;
case 'exact':
$sphinx->setMatchMode(SPH_MATCH_PHRASE);
break;
default:
$sphinx->setMatchMode(SPH_MATCH_ANY);
}
switch ($args['sort']) {
case 'date':
$sphinx->setSortMode(SPH_SORT_ATTR_DESC, 'date_added');
break;
case 'title':
$sphinx->setSortMode(SPH_SORT_ATTR_ASC, 'title');
break;
default:
$sphinx->setSortMode(SPH_SORT_RELEVANCE);
}
$page = isset($args['paged']) && intval($args['paged']) > 0 ? intval($args['paged']) : 1;
$per_page = max(array($args['posts_per_page'], $args['showposts']));
if ($per_page < 1) {
$per_page = get_option('posts_per_page');
}
$sphinx->setLimits(($page - 1) * $per_page, $per_page);
$sphinx->setMaxQueryTime(intval($options['timeout']));
$result = $sphinx->query($search, $options['index']);
$this->last_error = $sphinx->getLastError();
$this->last_warning = $sphinx->getLastWarning();
return $result;
}
示例14: SphinxClient
6、对查询关键字做特殊处理(标红)
7、匹配模式
8、权重排序
9、排除一些影响元素
10、添加新词
11、实时索引
12、删除数据
13、sphinx分页
*/
header("content-type:text/html;charset=utf-8");
include './sphinxapi.php';
$key = $_GET['keyword'];
$sp = new SphinxClient();
$sp->setServer('localhost', 9312);
//改变关键字匹配模式 SPH_MATCH_EXTENDED2支持权重排序
$sp->setMatchMode(SPH_MATCH_EXTENDED2);
//改变搜索排序模式 sphinx自带id weight 前面加@ 和表关联的字段不用加,优先级前后关系
$sp->setSortMode(SPH_SORT_EXTENDED, 'weight desc @weight desc');
//筛选指定字段的指定值保留,其他不显示
$sp->setFilter('status', array(1));
//分页
$sp->setLimits(4, 4);
//搜索根据相关索引
$result = $sp->query($key, 'ind_post ind_post_new');
echo "<pre>";
print_r($result['matches']);
$ids = implode(",", array_keys($result['matches']));
mysql_connect("localhost", "root", "123");
mysql_select_db("test");
mysql_set_charset("utf8");
echo $sql = "select * from post where id in (" . $ids . ") order by field(id," . $ids . ")";
示例15: function
/* Codeine
* @author bergstein@trickyplan.com
* @description Sphinx Driver
* @package Codeine
* @version 8.x
*/
setFn('Query', function ($Call) {
$Data = null;
// Собственно поиск
$Sphinx = new SphinxClient();
if ($Sphinx->setServer($Call['Server'], $Call['Port'])) {
// ищем хотя бы 1 слово из поисковой фразы
// FIXME Добавить опций
$Sphinx->setLimits($Call['Limits']['From'], $Call['Limits']['To'], $Call['Limits']['To']);
if ($Sphinx->setMatchMode(SPH_MATCH_ANY)) {
// поисковый запрос
if ($Result = $Sphinx->query($Call['Query'], strtolower($Call['Entity']))) {
if ($Result['total'] > 0) {
$Data = [];
foreach ($Result['matches'] as $ID => $Match) {
$Data[$ID] = $Match['weight'];
}
}
} else {
$Call = F::Hook('Sphinx.FailedQuery', $Call);
}
} else {
$Call = F::Hook('Sphinx.FailedMode', $Call);
}
} else {