本文整理汇总了PHP中SphinxClient::SetArrayResult方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::SetArrayResult方法的具体用法?PHP SphinxClient::SetArrayResult怎么用?PHP SphinxClient::SetArrayResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::SetArrayResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SphinxClient
/**
* Constructor.
*
* @param string $host The server's host name/IP.
* @param string $port The port that the server is listening on.
* @param array $indexes The list of indexes that can be used.
*/
function __construct()
{
//sphinx
$sphinxconf = Yaf_Registry::get("config")->get('sphinx')->toArray();
$this->host = $sphinxconf['host'];
$this->port = $sphinxconf['port'];
$this->indexes = $sphinxconf['indexes'];
$this->sphinx = new SphinxClient();
$this->sphinx->SetServer($this->host, $this->port);
//sphinx连接超时时间,单位为秒
$this->sphinx->SetConnectTimeout(5);
//sphinx搜索结果集返回方式:TRUE为普通数组返回,FALSE为PHP hash格式返回
$this->sphinx->SetArrayResult(false);
//sphinx最大搜索时间,单位为毫秒
$this->sphinx->SetMaxQueryTime(5000);
//匹配模式
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
//设置权重评分模式,详见sphinx文档第6.3.2节:SetRankingMode
$this->sphinx->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
//设置排序模式排序模式
$this->sphinx->SetSortMode(SPH_SORT_EXTENDED, '@weight DESC,@id DESC');
//中文分词配置
$httpcwsconf = Yaf_Registry::get("config")->get('httpcws')->toArray();
//中文分词HTTPCWS服务器接口地址
$this->httpcws_url = 'http://' . $httpcwsconf['host'] . ':' . $httpcwsconf['port'] . '/?w=';
}
示例2: _initSphinx
/**
* 初始化搜索引擎
*/
private function _initSphinx()
{
$this->_loadCore('Help_SphinxClient');
$this->_sphinx = new SphinxClient();
$this->_sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
$this->_sphinx->SetConnectTimeout(5);
//连接时间
$this->_sphinx->SetArrayResult(true);
$this->_sphinx->SetMaxQueryTime(10);
//设置最大超时时间
$this->_sphinx->SetMatchMode(SPH_MATCH_ANY);
//匹配模式
}
示例3: _initSphinx
/**
* 初始化搜索引擎
*/
private function _initSphinx()
{
import('@.Util.SphinxClient');
$this->_sphinx = new SphinxClient();
$this->_sphinx->SetServer(C('SPHINX_HOST'), C('SPHINX_PORT'));
$this->_sphinx->SetConnectTimeout(5);
//连接时间
$this->_sphinx->SetArrayResult(true);
//设置数组返回
$this->_sphinx->SetMaxQueryTime(10);
//设置最大超时时间
$this->_sphinx->SetMatchMode(SPH_MATCH_ANY);
//匹配模式
}
示例4: 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);
}
示例5: SphinxClient
function hook_search($search)
{
$offset = 0;
$limit = 500;
$sphinxClient = new SphinxClient();
$sphinxpair = explode(":", SPHINX_SERVER, 2);
$sphinxClient->SetServer($sphinxpair[0], (int) $sphinxpair[1]);
$sphinxClient->SetConnectTimeout(1);
$sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, 'feed_title' => 20));
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$sphinxClient->SetLimits($offset, $limit, 1000);
$sphinxClient->SetArrayResult(false);
$sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
$result = $sphinxClient->Query($search, SPHINX_INDEX);
$ids = array();
if (is_array($result['matches'])) {
foreach (array_keys($result['matches']) as $int_id) {
$ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
array_push($ids, $ref_id);
}
}
$ids = join(",", $ids);
if ($ids) {
return array("ref_id IN ({$ids})", array());
} else {
return array("ref_id = -1", array());
}
}
示例6: __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;
}
示例7: __construct
public function __construct()
{
parent::__construct();
$this->infohash_model = new InfohashModel();
$sphinx = new SphinxClient();
$sphinx->SetServer(Config::get('app.sphinx.host'), Config::get('app.sphinx.port'));
$sphinx->SetArrayResult(true);
$this->sphinx = $sphinx;
}
示例8: __construct
public function __construct(Application $app, $host, $port, $rt_host, $rt_port)
{
$this->app = $app;
$this->sphinx = new \SphinxClient();
$this->sphinx->SetServer($host, $port);
$this->sphinx->SetArrayResult(true);
$this->sphinx->SetConnectTimeout(1);
$this->suggestionClient = new \SphinxClient();
$this->suggestionClient->SetServer($host, $port);
$this->suggestionClient->SetArrayResult(true);
$this->suggestionClient->SetConnectTimeout(1);
try {
$this->rt_conn = @new \PDO(sprintf('mysql:host=%s;port=%s;', $rt_host, $rt_port));
$this->rt_conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
$this->rt_conn = null;
}
return $this;
}
示例9: _getSphinxClient
private function _getSphinxClient()
{
require_once SCRIPT_BASE . 'lib/sphinx-2.1.9/sphinxapi.php';
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer('127.0.0.1', 9312);
$sphinxClient->SetConnectTimeout(20);
$sphinxClient->SetArrayResult(true);
$sphinxClient->SetWeights(array(1000, 1));
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED);
return $sphinxClient;
}
示例10: __construct
/**
* __construct()
* 构造函数
*/
public function __construct()
{
parent::__construct();
parent::SetServer(SPH_HOST, 9312);
//parent::SetServer("localhost",9312);
//parent::SetConnectTimeout(10);
parent::SetMatchMode(SPH_MATCH_EXTENDED2);
//parent::SetFieldWeights($this->weights);
parent::SetRankingMode(SPH_RANK_WORDCOUNT);
//
parent::SetSortMode(SPH_SORT_EXTENDED, '@weight desc');
parent::SetArrayResult(TRUE);
$this->SetLimits($this->offset, $this->limit);
}
示例11: 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("*");
}
示例12: 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;
}
示例13: 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;
}
示例14: sphinxSearch
/**
* sphinx search
*/
public function sphinxSearch(Request $request, \SphinxClient $sphinx)
{
$search = $request->get('search');
//sphinx的主机名和端口 //mysql -h 127.0.0.1 -P 9306
$sphinx->SetServer('127.0.0.1', 9312);
//设定搜索模式 SPH_MATCH_ALL(匹配所有的查询词)
$sphinx->SetMatchMode(SPH_MATCH_ALL);
//设置返回结果集为数组格式
$sphinx->SetArrayResult(true);
//匹配结果的偏移量,参数的意义依次为:起始位置,返回结果条数,最大匹配条数
$sphinx->SetLimits(0, 20, 1000);
//最大搜索时间
$sphinx->SetMaxQueryTime(10);
//索引源是配置文件中的 index 类,如果有多个索引源可使用,号隔开:'email,diary' 或者使用'*'号代表全部索引源
$result = $sphinx->query($search, '*');
//返回值说明 total 本次查询返回条数 total_found 一共检索到多少条 docs 在多少文档中出现 hits——共出现了多少次
//关闭查询连接
$sphinx->close();
//打印结果
/*echo "<pre>";
print_r($result);
echo "</pre>";exit();*/
$ids = [0];
if (!empty($result)) {
foreach ($result['matches'] as $key => $val) {
$ids[] = $val['id'];
}
}
$ids = implode(',', array_unique($ids));
$list = DB::select("SELECT * from documents WHERE id IN ({$ids})");
if (!empty($list)) {
foreach ($list as $key => $val) {
$val->content = str_replace($search, '<span style="color: red;">' . $search . '</span>', $val->content);
$val->title = str_replace($search, '<span style="color: red;">' . $search . '</span>', $val->title);
}
}
return view('/sphinx.search')->with('data', array('total' => $result['total'] ? $result['total'] : 0, 'time' => $result['time'] ? $result['time'] : 0, 'list' => $list));
}
示例15: 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;
}
}