本文整理汇总了PHP中SphinxClient::setLimits方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::setLimits方法的具体用法?PHP SphinxClient::setLimits怎么用?PHP SphinxClient::setLimits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::setLimits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resetClient
/**
* Reset settings sphinx
*/
public function resetClient()
{
$this->_client->resetFilters();
$this->_client->resetGroupBy();
$this->_client->setArrayResult(false);
//DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
//$this->_client->setMatchMode(SPH_MATCH_EXTENDED2);
$this->_client->setLimits(0, 20, 1000, 0);
$this->_client->setFieldWeights(array());
$this->_client->setSortMode(SPH_SORT_RELEVANCE, '');
$this->_client->_error = '';
$this->_client->_warning = '';
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: search
/**
* Search for the specified query string.
*
* @param string $query The query string that we are searching for.
* @param array $indexes The indexes to perform the search on.
* @param array $options The options for the query.
* @param bool $escapeQuery Should the query string be escaped?
*
* @return array The results of the search.
*/
public function search($query, array $indexes, array $options = array(), $escapeQuery = true)
{
if ($escapeQuery) {
$query = $this->sphinx->escapeString($query);
}
/**
* Build the list of indexes to be queried.
*/
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
/**
* If no valid indexes were specified, return an empty result set.
*
* FIXME: This should probably throw an exception.
*/
if (empty($indexNames)) {
return array();
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$start = round(microtime(true) * 1000);
$results = $this->sphinx->query($query, $indexNames);
if ($results['status'] === SEARCHD_ERROR) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
if ($results['status'] === SEARCHD_RETRY) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with retry "%s".', $label, $query, $this->sphinx->getLastError()));
}
$end = round(microtime(true) * 1000) - $start;
$event = new SearchEvent($query, $indexes, $end);
$this->dispatcher->dispatch("sphinx.event.search", $event);
return $results;
}
示例6: __construct
public function __construct($query)
{
$this->query = $query;
$max_results = intval(SphinxSearch_Config_Plugin::getValue("results", "maxresults"));
$this->limit = $max_results;
$SphinxClient = new SphinxClient();
$this->SphinxClient = $SphinxClient;
$SphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
$SphinxClient->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
$SphinxClient->setServer("localhost", SphinxSearch_Config_Plugin::getValue("searchd", "port"));
// Sphinx Client is to always return everything - it's just IDs
// Paginator is then to cast the necessary Items, this can be done
// with offset/limit
$SphinxClient->setLimits(0, $max_results, $max_results);
}
示例7: search
/**
* Search for the specified query string.
*
* @param string $query The query string that we are searching for.
* @param array $indexes The indexes to perform the search on.
*
* @return array The results of the search.
*
* $indexes should look like:
*
* $indexes = array(
* 'IndexLabel' => array(
* 'result_offset' => (int), // optional unless result_limit is set
* 'result_limit' => (int), // optional unless result_offset is set
* 'field_weights' => array( // optional
* 'FieldName' => (int),
* ...,
* ),
* ),
* ...,
* );
*/
public function search($query, array $indexes, $escapeQuery = true)
{
if ($escapeQuery) {
$query = $this->sphinx->escapeString($query);
}
$results = array();
foreach ($indexes as $label => $options) {
/**
* Ensure that the label corresponds to a defined index.
*/
if (!isset($this->indexes[$label])) {
continue;
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
if ($results[$label]['status'] !== SEARCHD_OK) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
}
/**
* If only one index was searched, return that index's results directly.
*/
if (count($indexes) === 1 && count($results) === 1) {
$results = reset($results);
}
/**
* FIXME: Throw an exception if $results is empty?
*/
return $results;
}
示例8: _query
/**
* Отправляет подготовленный запрос на сфинкс, и преобразует ответ в нужный вид.
*
* @param string $query поисковый запрос (в оригинальном виде)
* @param int $storeId ИД текущего магазина
* @param string $indexCode Код индекса по которому нужно провести поиск (mage_catalog_product ...)
* @param string $primaryKey Primary Key индекса (entity_id, category_id, post_id ...)
* @param array $attributes Масив атрибутов с весами
* @param int $offset Страница
*
* @return array масив ИД елементов, где ИД - ключ, релевантность значение
*/
protected function _query($query, $storeId, $index, $offset = 1)
{
$uid = Mage::helper('mstcore/debug')->start();
$indexCode = $index->getCode();
$primaryKey = $index->getPrimaryKey();
$attributes = $index->getAttributes();
$client = new SphinxClient();
$client->setMaxQueryTime(5000);
//5 seconds
$client->setLimits(($offset - 1) * self::PAGE_SIZE, self::PAGE_SIZE, $this->_config->getResultLimit());
$client->setSortMode(SPH_SORT_RELEVANCE);
$client->setMatchMode(SPH_MATCH_EXTENDED);
$client->setServer($this->_spxHost, $this->_spxPort);
$client->SetFieldWeights($attributes);
if ($storeId) {
$client->SetFilter('store_id', $storeId);
}
$sphinxQuery = $this->_buildQuery($query, $storeId);
if (!$sphinxQuery) {
return array();
}
$sphinxQuery = '@(' . implode(',', $index->getSearchableAttributes()) . ')' . $sphinxQuery;
$sphinxResult = $client->query($sphinxQuery, $indexCode);
if ($sphinxResult === false) {
Mage::throwException($client->GetLastError() . "\nQuery: " . $query);
} elseif ($sphinxResult['total'] > 0) {
$entityIds = array();
foreach ($sphinxResult['matches'] as $data) {
$entityIds[$data['attrs'][strtolower($primaryKey)]] = $data['weight'];
}
if ($sphinxResult['total'] > $offset * self::PAGE_SIZE && $offset * self::PAGE_SIZE < $this->_config->getResultLimit()) {
$newIds = $this->_query($query, $storeId, $index, $offset + 1);
foreach ($newIds as $key => $value) {
$entityIds[$key] = $value;
}
}
} else {
$entityIds = array();
}
$entityIds = $this->_normalize($entityIds);
Mage::helper('mstcore/debug')->end($uid, $entityIds);
return $entityIds;
}
示例9: getSphinxAdapter
public function getSphinxAdapter()
{
require_once Mage::getBaseDir('lib') . DIRECTORY_SEPARATOR . 'sphinxapi.php';
// Connect to our Sphinx Search Engine and run our queries
$sphinx = new SphinxClient();
$host = Mage::getStoreConfig('sphinxsearch/server/host');
$port = Mage::getStoreConfig('sphinxsearch/server/port');
if (empty($host)) {
return $sphinx;
}
if (empty($port)) {
$port = 9312;
}
$sphinx->SetServer($host, $port);
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->setFieldWeights(array('name' => 7, 'category' => 1, 'name_attributes' => 1, 'data_index' => 3));
$sphinx->setLimits(0, 200, 1000, 5000);
// SPH_RANK_PROXIMITY_BM25 ist default
$sphinx->SetRankingMode(SPH_RANK_SPH04, "");
// 2nd parameter is rank expr?
return $sphinx;
}
示例10: search
/**
* Search for the specified query string.
*
* @param string $query The query string that we are searching for.
* @param array $indexes The indexes to perform the search on.
*
* @return ResultCollection The results of the search.
*
* $indexes should have the format:
*
* $indexes = array(
* 'IndexLabel' => array(
* 'result_offset' => (int),
* 'result_limit' => (int)
* ),
* ...,
* );
*/
public function search($query, array $indexes)
{
// $query = $this->sphinx->escapeString($query);
$results = array();
foreach ($indexes as $label => $options) {
/**
* Ensure that the label corresponds to a defined index.
*/
if (!isset($this->indexes[$label])) {
continue;
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit']) && is_numeric($options['result_offset']) && is_numeric($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (!empty($this->indexes[$label]['field_weights'])) {
$this->sphinx->setFieldWeights($this->indexes[$label]['field_weights']);
}
/**
* Perform the query.
*/
$results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
if ($this->sphinx->IsConnectError()) {
throw new ConnectionException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
} elseif ($results[$label]['status'] !== SEARCHD_OK) {
throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
}
}
/**
* FIXME: Throw an exception if $results is empty?
*/
return new ResultCollection($results, $this->mapping, $this->em);
}
示例11: SphinxClient
}
$cl = new SphinxClient();
// 返回结果设置
$cl->SetServer('192.168.25.129', 9312);
$cl->SetConnectTimeout(3);
$cl->SetArrayResult(true);
// 设置是否全文匹配
if (!empty($_GET) && !empty($_GET['f'])) {
$cl->SetMatchMode(SPH_MATCH_ANY);
}
if (!empty($_GET) && !empty($_GET['p'])) {
$p = !intval(trim($_GET['p'])) == 0 ? intval(trim($_GET['p'])) - 1 : 0;
$p = $p * 20;
// 我在sed.conf 设置了最大返回结果数1000。但是我在生成页码的时候最多生成20页,我想能满足大部分搜索需求了。
// 以下语句表示从P参数偏移开始每次返回20条。
$cl->setLimits($p, 20);
} else {
$cl->setLimits(0, 20);
}
$res = $cl->Query("{$Keywords}", "*");
//var_dump($res);
@mysql_connect("localhost", "test", "mima");
//数据库账号密码
mysql_select_db("test");
//数据库库名名
mysql_query("set names utf8");
$tables = ['spdb1', 'spdb2', 'spdb3', 'spdb4', 'spdb5'];
//把表名放入数组
function getResult($id, $table)
{
$sql = "select username,email,password,salt,site from {$table} where id = " . $id;
示例12: showmessage
showmessage('search_forum_invalid', 'search.php?mod=forum');
} elseif (!$fids) {
showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
}
if ($_G['adminid'] != '1' && $_G['setting']['search']['forum']['maxspm']) {
if (DB::result_first("SELECT COUNT(*) FROM " . DB::table('common_searchindex') . " WHERE srchmod='{$srchmod}' AND dateline>'{$_G['timestamp']}'-60") >= $_G['setting']['search']['forum']['maxspm']) {
showmessage('search_toomany', 'search.php?mod=forum', array('maxspm' => $_G['setting']['search']['forum']['maxspm']));
}
}
if ($srchtype == 'fulltext' && $_G['setting']['sphinxon']) {
require_once libfile('class/sphinx');
$s = new SphinxClient();
$s->setServer($_G['setting']['sphinxhost'], intval($_G['setting']['sphinxport']));
$s->setMaxQueryTime(intval($_G['setting']['sphinxmaxquerytime']));
$s->SetRankingMode($_G['setting']['sphinxrank']);
$s->setLimits(0, intval($_G['setting']['sphinxlimit']), intval($_G['setting']['sphinxlimit']));
$s->setGroupBy('tid', SPH_GROUPBY_ATTR);
if ($srchfilter == 'digest') {
$s->setFilterRange('digest', 1, 3, false);
}
if ($srchfilter == 'top') {
$s->setFilterRange('displayorder', 1, 2, false);
} else {
$s->setFilterRange('displayorder', 0, 2, false);
}
if (!empty($srchfrom) && empty($srchtxt) && empty($srchuid) && empty($srchuname)) {
$expiration = TIMESTAMP + $cachelife_time;
$keywords = '';
if ($before) {
$spx_timemix = 0;
$spx_timemax = TIMESTAMP - $srchfrom;
示例13: getRecipes
function getRecipes($advanced)
{
include __ROOT__ . "sphinx/api.php";
$cl = new SphinxClient();
$cl->SetServer("localhost", 9312);
$l = isset($advanced['limit']) ? $advanced['limit'] : 10;
$limit = isset($advanced['page']) ? (int) $advanced['page'] * $l : 0;
$cl->setLimits($limit, $l + 1);
$lang_id = 0;
if ($advanced['favorites'] == 1 && VF::app()->user->isAuth()) {
$ids_a = array();
$ids = VF::app()->database->sql("SELECT recipe_id FROM recipes_likes WHERE user_id = " . VF::app()->user->getId())->queryAll();
foreach ($ids as $i) {
$ids_a[] = $i['recipe_id'];
}
if (empty($ids_a)) {
return array();
}
$cl->setFilter('id_attr', $ids_a);
} else {
if (isset($advanced['lang_id'])) {
$lang_id = $advanced['lang_id'];
} else {
$lang_id = VF::app()->lang_id;
}
}
if ($advanced['country_id'] > 0) {
$cl->setFilter('country_id', array($advanced['country_id']));
}
if ($advanced['category_id'] > 0) {
$cl->setFilter('category_id', array($advanced['category_id']));
$lang_id = 0;
}
if ($lang_id > 0) {
$cl->setFilter('lang_id', array($lang_id));
}
if (!empty($advanced['ingredient_id'])) {
$ids_a = array();
$a = explode(",", $advanced['ingredient_id']);
if (count($a) > 1) {
$sql = "SELECT recipe_id, count(Distinct ingredient_id)\n FROM recipes2ingredients\n WHERE ingredient_ID in (" . $advanced['ingredient_id'] . ")\n GROUP BY recipe_id\n HAVING count(Distinct ingredient_id) = " . count($a);
} else {
$sql = "SELECT recipe_id FROM recipes2ingredients WHERE ingredient_id = " . $advanced['ingredient_id'] . " LIMIT 300";
}
$ids = VF::app()->database->sql($sql)->queryAll();
foreach ($ids as $i) {
$ids_a[] = $i['recipe_id'];
}
$cl->setFilter('id_attr', $ids_a);
}
if (!empty($advanced['query'])) {
$results = $cl->Query($advanced['query']);
// поисковый запрос
} else {
$cl->SetMatchMode(SPH_MATCH_FULLSCAN);
// ищем хотя бы 1 слово из поисковой фразы
$cl->setSortMode(SPH_SORT_ATTR_DESC, 'date_created');
$results = $cl->Query('*');
// поисковый запрос
}
$this->total_found = $results['total_found'];
$arr = array();
if (!empty($results['matches'])) {
foreach ($results['matches'] as $r) {
$r['attrs']['id'] = $r['attrs']['id_attr'];
$arr[] = $r['attrs'];
}
}
return $arr;
}
示例14: function
<?php
/* 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);
}
示例15: bindToSphinx
/**
* @param \SphinxClient $sphinx
*/
public function bindToSphinx(\SphinxClient $sphinx)
{
$sphinx->setLimits($this->getOffset(), $this->getLimit(), $this->getMaxResults());
}