当前位置: 首页>>代码示例>>PHP>>正文


PHP SphinxClient类代码示例

本文整理汇总了PHP中SphinxClient的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient类的具体用法?PHP SphinxClient怎么用?PHP SphinxClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SphinxClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init_sphinx

 /**
  * Sphinx server connector initialization
  * 
  * @return SphinxClient
  */
 function init_sphinx()
 {
     $this->sphinx = new SphinxClient();
     $this->sphinx->SetServer($this->admin_options['sphinx_host'], intval($this->admin_options['sphinx_port']));
     $this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
     return $this->sphinx;
 }
开发者ID:pierredewit,项目名称:WordPress-Sphinx-Search-plugin,代码行数:12,代码来源:sphinxsearch_config.php

示例2: hook_search

 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());
     }
 }
开发者ID:zamentur,项目名称:ttrss_ynh,代码行数:29,代码来源:init.php

示例3: getInstance

 public static function getInstance($sphinxconf, $type = 'media')
 {
     $time = microtime(true);
     $rand = intval(substr($time, 11, 4));
     $num = count($sphinxconf);
     $index = $rand % $num;
     $ret = false;
     if (null == self::$_sphinxpool[$type]) {
         $try_count = 0;
         while ($try_count < 3 && $ret != true) {
             $client = new SphinxClient();
             $index = $index % $num;
             try {
                 $client->setServer($sphinxconf[$index]['host'], $sphinxconf[$index]['port']);
                 self::$_index[$type] = $sphinxconf[$index]['indexer'];
                 $ret = $client->Open();
                 if ($ret == true) {
                     self::$_conf_num[$type] = $index;
                     break;
                 }
                 Systemlog::fatal("sphinx connect fail time:" . $client->_host . " " . $client->_port);
                 $try_count++;
                 $index++;
             } catch (Exception $e) {
                 $index++;
                 $try_count++;
             }
         }
         self::$_sphinxpool[$type] = $client;
     }
     return self::$_sphinxpool[$type];
 }
开发者ID:glianyi,项目名称:MyPHP,代码行数:32,代码来源:sphinxha.php

示例4: __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;
 }
开发者ID:supertanglang,项目名称:dht,代码行数:9,代码来源:SearchController.php

示例5: sphinx_add_result_forum

function sphinx_add_result_forum($items) {
    $inCore = cmsCore::getInstance();

    global $_LANG;
    cmsCore::loadLanguage('components/forum');
    $config = $inCore->loadComponentConfig('forum');
    $search_model = cms_model_search::initModel();
    
    foreach ($items as $id => $item) {
        if (!cmsCore::checkContentAccess($item['attrs']['access_list'])) { continue; }
            
        $pages = ceil($item['attrs']['post_count'] / $config['pp_thread']);

        $result_array = array(
            'link' => '/forum/thread'. $id .'-'. $pages .'.html',
            'place' => $item['attrs']['forum'],
            'placelink' => '/forum/'. $item['attrs']['forum_id'],
            'description' => $search_model->getProposalWithSearchWord($item['attrs']['description']),
            'title' => $item['attrs']['title'],
            'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate'])
        );

        $search_model->addResult($result_array);
    }
    
    // Ищем в тексте постов
    
    $cl = new SphinxClient();

    $cl->SetServer('127.0.0.1', 9312);
    $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
    $cl->SetLimits(0, 100);
    
    $result = $cl->Query($search_model->against, $search_model->config['Sphinx_Search']['prefix'] .'_forum_posts');
            
    if ($result !== false) {
        foreach ($result['matches'] as $id => $item) {
            $pages = ceil($item['attrs']['post_count'] / $config['pp_thread']);
            $post_page = ($pages > 1) ? postPage::getPage($item['attrs']['thread_id'], $id, $config['pp_thread']) : 1;
            
            $result_array = array(
                'link' => '/forum/thread'. $item['attrs']['thread_id'] .'-'. $post_page .'.html#'. $id,
                'place' => $_LANG['FORUM_POST'],
                'placelink' => '/forum/thread'. $item['attrs']['thread_id'] .'-'. $post_page .'.html#'. $id,
                'description' => $search_model->getProposalWithSearchWord($item['attrs']['content_html']),
                'title' => $item['attrs']['thread'],
                'imageurl' => $item['attrs']['fileurl'],
                'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate'])
            );

            $search_model->addResult($result_array);
        }
    }
    
    return;
}
开发者ID:Acsac,项目名称:CMS-RuDi,代码行数:56,代码来源:sphinx_psearch.php

示例6: setup

 /**
  * do driver instance init
  */
 public function setup()
 {
     $settings = $this->getSettings();
     if (empty($settings)) {
         throw new BoxRouteInstanceException('init driver instance failed: empty settings');
     }
     $curInst = new \SphinxClient();
     $curInst->setServer($settings['sphinxHost'], $settings['sphinxPort']);
     !empty($settings['sphinxConnectTimeout']) && $curInst->setConnectTimeout($settings['sphinxConnectTimeout']);
     $this->instance = $curInst;
     $this->isAvailable = $this->instance ? true : false;
 }
开发者ID:nickfan,项目名称:appbox,代码行数:15,代码来源:SphinxBoxRouteInstanceDriver.php

示例7: sphinx_client

function sphinx_client()
{
    global $globals, $db;
    static $cl = false;
    if (!$cl) {
        $cl = new SphinxClient();
        $cl->SetServer($globals['sphinx_server'], $globals['sphinx_port']);
        // Request for status values, it's used in other sites
        $globals['status_values'] = $db->get_enum_values('links', 'link_status');
    }
    return $cl;
}
开发者ID:GallardoAlba,项目名称:Meneame,代码行数:12,代码来源:search.php

示例8: getSphinxClient

 /**
  * @return SphinxClient
  */
 public function getSphinxClient()
 {
     if (null === $this->_sphinxClient) {
         if (!class_exists("SphinxClient")) {
             $this->load->library('sphinx/sphinxapi');
         }
         $sphinxClient = new SphinxClient();
         $sphinxClient->SetServer($this->config->get('sphinx_search_server'), $this->config->get('sphinx_search_port'));
         $sphinxClient->SetConnectTimeout(1);
         //$sphinxClient->_mbenc = "UTF-8";
         $sphinxClient->ResetFilters();
         $this->_sphinxClient = $sphinxClient;
     }
     return $this->_sphinxClient;
 }
开发者ID:kotetsky,项目名称:store,代码行数:18,代码来源:sphinx.php

示例9: new_sphinx

function new_sphinx()
{
    global $CONF;
    if ($CONF['unit_test_active']) {
        return new DummySphinx();
    } else {
        if (!$CONF['sphinx']) {
            return NULL;
        } else {
            $sphinx = new SphinxClient();
            $sphinx->SetServer($CONF['sphinx_host'], $CONF['sphinx_port']);
            return $sphinx;
        }
    }
}
开发者ID:bufvc,项目名称:bufvc-potnia-framework,代码行数:15,代码来源:sphinx.inc.php

示例10: sphinx_add_result_clubs

function sphinx_add_result_clubs($items) {
    global $_LANG;
    
    cmsCore::m('clubs');
    $search_model = cms_model_search::initModel();
    
    foreach ($items as $id => $item) {
        $result_array = array(
            'link' => cmsCore::m('clubs')->getPostURL($item['attrs']['user_id'], $item['attrs']['seolink']),
            'place' => ' &laquo;'. $item['attrs']['cat_title'] .'&raquo;',
            'placelink' => cmsCore::m('clubs')->getBlogURL($item['attrs']['user_id']),
            'description' => $search_model->getProposalWithSearchWord($item['attrs']['content_html']),
            'title' => $item['attrs']['title'],
            'imageurl' => $item['fileurl'],
            'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate'])
        );

        $search_model->addResult($result_array);
    }
    
    /////// поиск по клубным фоткам //////////
    $cl = new SphinxClient();

    $cl->SetServer('127.0.0.1', 9312);
    $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
    $cl->SetLimits(0, 100);
    
    $result = $cl->Query($search_model->against, $search_model->config['Sphinx_Search']['prefix'] .'_clubs_photos');
            
    if ($result !== false) {
        foreach ($result['matches'] as $id => $item) {
            $result_array = array(
                'link' => '/clubs/photo'. $id .'.html',
                'place' => $_LANG['CLUBS_PHOTOALBUM'] .' &laquo;'. $item['attrs']['cat_title'] .'&raquo;',
                'placelink' => '/clubs/photoalbum'. $item['attrs']['cat_id'],
                'description' => $search_model->getProposalWithSearchWord($item['attrs']['description']),
                'title' => $item['attrs']['title'],
                'imageurl' => (file_exists(PATH .'/images/photos/medium/'. $item['attrs']['file']) ? '/images/photos/medium/'. $item['attrs']['file'] : ''),
                'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate'])
            );

            $search_model->addResult($result_array);
        }
    }
    
    return;
}
开发者ID:Acsac,项目名称:CMS-RuDi,代码行数:47,代码来源:sphinx_psearch.php

示例11: setFilter

 /**
  * Adds new integer values set filter to the existing list of filters.
  *
  * @param $attribute An attribute name.
  * @param $values Plain array of integer values.
  * @param bool $exclude If set to TRUE, matching items are excluded from the result set.
  * @return SphinxSearch_Abstract_List
  * @throws Exception on failure
  */
 public function setFilter($attribute, $values, $exclude = false)
 {
     $result = $this->SphinxClient->SetFilter($attribute, $values, $exclude);
     if ($result === false) {
         throw new Exception("Error on setting filter \"" . $attribute . "\":\n" . $this->SphinxClient->GetLastError());
     }
     return $this;
 }
开发者ID:VadzimBelski-ScienceSoft,项目名称:pimcore-plugin-SphinxSearch,代码行数:17,代码来源:List.php

示例12: _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;
 }
开发者ID:vishalpatel14,项目名称:indiankalaniketan,代码行数:55,代码来源:Sphinx.php

示例13: 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;
 }
开发者ID:OranTing,项目名称:gdby_github_repo,代码行数:56,代码来源:spider_anti.php

示例14: __construct

 public function __construct()
 {
     parent::SphinxClient();
     $ci = get_instance();
     $ci->load->config('sphinx', TRUE);
     $this->config = $ci->config->item('sphinx');
     foreach ($this->config as $k => $i) {
         @call_user_func_array(array($this, 'Set' . $k), $i);
     }
     $this->SetSortMode(SPH_SORT_EXTENDED, '@weight DESC, @id DESC');
 }
开发者ID:ilei,项目名称:blog,代码行数:11,代码来源:Sphinx.php

示例15: executeSearch

 public function executeSearch(sfWebRequest $request)
 {
     $q = $request->getParameter('q');
     include '/home/jackbravo/work/sphinx-0.9.9-rc1/api/sphinxapi.php';
     $s = new SphinxClient();
     $result = $s->query($q);
     if ($result['total'] > 0) {
         $query = Doctrine::getTable('Issue')->findIdsQuery(array_keys($result['matches']));
     } else {
         $query = Doctrine::getTable('Issue')->findNullQuery();
     }
     $pager = new sfDoctrinePager('Issue', sfConfig::get('app_max_issues_on_index'));
     $pager->setQuery($query);
     $pager->setPage($request->getParameter('page', 1));
     $pager->setTableMethod('getListQuery');
     $pager->init();
     $this->filter = $this->getFilter($request);
     $this->pager = $pager;
     $this->from_search = $q;
     $this->setTemplate('index');
 }
开发者ID:jackbravo,项目名称:amaranto,代码行数:21,代码来源:actions.class.php


注:本文中的SphinxClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。