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


PHP SphinxClient::SetFilter方法代码示例

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


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

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

示例2: applyFilters

 protected function applyFilters(array $conditions, $exclude = false)
 {
     $exclude = (bool) $exclude;
     foreach ($conditions as $field => $values) {
         $this->sphinxClient->SetFilter($field, $values, $exclude);
     }
 }
开发者ID:jerrylsxu,项目名称:yii-sphinx,代码行数:7,代码来源:ESphinxConnection.php

示例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);
 }
开发者ID:ntemple,项目名称:intelli-plancake,代码行数:32,代码来源:Searcher.php

示例4: search

 /**
  * 搜索faq
  * @param string $keywords 搜索的字符串
  * @param int $gameId	游戏ID
  * @param int $kindId	分类ID
  */
 public function search($keywords, $gameId = null, $kindId = null)
 {
     $this->_sphinx->SetFilter('lang_id', array(C('LANG_ID')), false);
     //设置语言为简体
     if (is_numeric($gameId)) {
         $this->_sphinx->SetFilter('game_type_id', array($gameId), false);
     }
     if (is_numeric($kindId)) {
         $this->_sphinx->SetFilter('kind_id', array($kindId), false);
     }
     if (is_numeric($this->_faqStatus)) {
         $this->_sphinx->SetFilter('status', array($this->_faqStatus), true);
     }
     $result = $this->_sphinx->Query($keywords);
     $retResult = array('data' => $this->_getResult($result['matches']), 'info' => array('total' => $result['total'], 'total_found' => $result['total_found'], 'time' => $result['time'], 'words' => $result['words']));
     return $retResult;
 }
开发者ID:huangwei2wei,项目名称:kfxt,代码行数:23,代码来源:FaqSearch.class.php

示例5: 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

示例6: filter

 /**
  * 设置属性过滤
  * $attribute, $values, $exclude = FALSE
  * 此调用在已有的过滤器列表中添加新的过滤器。$attribute是属性名。$values是整数数组。$exclude是布尔值,它控制是接受匹配的文档(默认模式,即$exclude为false时)还是拒绝它们。
  * 只有当索引中$attribute列的值与$values中的任一值匹配时文档才会被匹配(或者拒绝,如果$exclude值为true)
  */
 function filter($filter)
 {
     if (is_array($filter) && count($filter) > 0) {
         foreach ($filter as $attribute => $v) {
             list($values, $exclude) = explode(',', $v);
             $sphinx_int_array = explode("_", $values);
             $this->sphinx->SetFilter($attribute, $sphinx_int_array, constant($exclude));
         }
     }
     return $this;
 }
开发者ID:290329416,项目名称:guahao,代码行数:17,代码来源:sphinxsearch.php

示例7: FindContent

 /**
  * Непосредственно сам поиск
  *
  * @param string $sTerms	Поисковый запрос
  * @param string $sObjType	Тип поиска
  * @param int $iOffset	Сдвиг элементов
  * @param int $iLimit	Количество элементов
  * @param array $aExtraFilters	Список фильтров
  * @return array
  */
 public function FindContent($sTerms, $sObjType, $iOffset, $iLimit, $aExtraFilters)
 {
     /**
      * используем кеширование при поиске
      */
     $sExtraFilters = serialize($aExtraFilters);
     $cacheKey = Config::Get('module.search.entity_prefix') . "searchResult_{$sObjType}_{$sTerms}_{$iOffset}_{$iLimit}_{$sExtraFilters}";
     if (false === ($data = $this->Cache_Get($cacheKey))) {
         /**
          * Параметры поиска
          */
         $this->oSphinx->SetMatchMode(SPH_MATCH_ALL);
         $this->oSphinx->SetLimits($iOffset, $iLimit);
         /**
          * Устанавливаем атрибуты поиска
          */
         $this->oSphinx->ResetFilters();
         if (!is_null($aExtraFilters)) {
             foreach ($aExtraFilters as $sAttribName => $sAttribValue) {
                 $this->oSphinx->SetFilter($sAttribName, is_array($sAttribValue) ? $sAttribValue : array($sAttribValue));
             }
         }
         /**
          * Ищем
          */
         if (!is_array($data = $this->oSphinx->Query($sTerms, Config::Get('module.search.entity_prefix') . $sObjType . 'Index'))) {
             return FALSE;
             // Скорее всего недоступен демон searchd
         }
         /**
          * Если результатов нет, то и в кеш писать не стоит...
          * хотя тут момент спорный
          */
         if ($data['total'] > 0) {
             $this->Cache_Set($data, $cacheKey, array(), 60 * 15);
         }
     }
     return $data;
 }
开发者ID:lunavod,项目名称:bunker_stable,代码行数:49,代码来源:Sphinx.class.php

示例8: FindContent

 /**
  * Непосредственно сам поиск
  *
  * @param string $sQuery           Поисковый запрос
  * @param string $sObjType         Тип поиска
  * @param int    $iOffset          Сдвиг элементов
  * @param int    $iLimit           Количество элементов
  * @param array  $aExtraFilters    Список фильтров
  *
  * @return array
  */
 public function FindContent($sQuery, $sObjType, $iOffset, $iLimit, $aExtraFilters)
 {
     // * используем кеширование при поиске
     $sExtraFilters = serialize($aExtraFilters);
     $cacheKey = Config::Get('plugin.sphinx.prefix') . "searchResult_{$sObjType}_{$sQuery}_{$iOffset}_{$iLimit}_{$sExtraFilters}";
     if (false === ($data = E::ModuleCache()->Get($cacheKey))) {
         // * Параметры поиска
         $this->oSphinx->SetMatchMode(SPH_MATCH_ALL);
         $this->oSphinx->SetLimits($iOffset, $iLimit, 1000);
         // * Устанавливаем атрибуты поиска
         $this->oSphinx->ResetFilters();
         if (!is_null($aExtraFilters)) {
             foreach ($aExtraFilters as $sAttribName => $sAttribValue) {
                 $this->oSphinx->SetFilter($sAttribName, is_array($sAttribValue) ? $sAttribValue : array($sAttribValue));
             }
         }
         // * Ищем
         $sIndex = Config::Get('plugin.sphinx.prefix') . $sObjType . 'Index';
         $data = $this->oSphinx->Query($sQuery, $sIndex);
         if (!is_array($data)) {
             // Если false, то, скорее всего, ошибка и ее пишем в лог
             $sError = $this->GetLastError();
             if ($sError) {
                 $sError .= "\nquery:{$sQuery}\nindex:{$sIndex}";
                 if ($aExtraFilters) {
                     $sError .= "\nfilters:";
                     foreach ($aExtraFilters as $sAttribName => $sAttribValue) {
                         $sError .= $sAttribName . '=(' . (is_array($sAttribValue) ? join(',', $sAttribValue) : $sAttribValue) . ')';
                     }
                 }
                 $this->LogError($sError);
             }
             return false;
         }
         /**
          * Если результатов нет, то и в кеш писать не стоит...
          * хотя тут момент спорный
          */
         if ($data['total'] > 0) {
             E::ModuleCache()->Set($data, $cacheKey, array(), 60 * 15);
         }
     }
     return $data;
 }
开发者ID:AntiqS,项目名称:altocms,代码行数:55,代码来源:Sphinx.class.php

示例9: 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'])) {
                 //过滤模型
//.........这里部分代码省略.........
开发者ID:BGCX262,项目名称:ztoa-svn-to-git,代码行数:101,代码来源:IndexAction.class.php

示例10: 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;
    }
}
开发者ID:nmssoft,项目名称:search_service,代码行数:79,代码来源:search_service.php

示例11: __construct

 public function __construct($rowsPerPage, $currentPage, $siteID, $wildCardString, $sortBy, $sortDirection)
 {
     $this->_db = DatabaseConnection::getInstance();
     $this->_siteID = $siteID;
     $this->_sortByFields = array('firstName', 'lastName', 'city', 'state', 'dateModifiedSort', 'dateCreatedSort', 'ownerSort');
     if (ENABLE_SPHINX) {
         /* Sphinx API likes to throw PHP errors *AND* use it's own error
          * handling.
          */
         assert_options(ASSERT_WARNING, 0);
         $sphinx = new SphinxClient();
         $sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
         $sphinx->SetWeights(array(0, 100, 0, 0, 50));
         $sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
         $sphinx->SetLimits(0, 1000);
         $sphinx->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'date_added');
         // FIXME: This can be sped up a bit by actually grouping ranges of
         //        site IDs into their own index's. Maybe every 500 or so at
         //        least on the Hosted system.
         $sphinx->SetFilter('site_id', array($this->_siteID));
         /* Create the Sphinx query string. */
         $wildCardString = DatabaseSearch::humanToSphinxBoolean($wildCardString);
         /* Execute the Sphinx query. Sphinx can ask us to retry if its
          * maxed out. Retry up to 5 times.
          */
         $tries = 0;
         do {
             /* Wait for one second if this isn't out first attempt. */
             if (++$tries > 1) {
                 sleep(1);
             }
             $results = $sphinx->Query($wildCardString, SPHINX_INDEX);
             $errorMessage = $sphinx->GetLastError();
         } while ($results === false && strpos($errorMessage, 'server maxed out, retry') !== false && $tries <= 5);
         /* Throw a fatal error if Sphinx errors occurred. */
         if ($results === false) {
             $this->fatal('Sphinx Error: ' . ucfirst($errorMessage) . '.');
         }
         /* Throw a fatal error (for now) if Sphinx warnings occurred. */
         $lastWarning = $sphinx->GetLastWarning();
         if (!empty($lastWarning)) {
             // FIXME: Just display a warning, and notify dev team.
             $this->fatal('Sphinx Warning: ' . ucfirst($lastWarning) . '.');
         }
         /* Show warnings for assert()s again. */
         assert_options(ASSERT_WARNING, 1);
         if (empty($results['matches'])) {
             $this->_WHERE = '0';
         } else {
             $attachmentIDs = implode(',', array_keys($results['matches']));
             $this->_WHERE = 'attachment.attachment_id IN(' . $attachmentIDs . ')';
         }
     } else {
         $this->_WHERE = DatabaseSearch::makeBooleanSQLWhere(DatabaseSearch::fulltextEncode($wildCardString), $this->_db, 'attachment.text');
     }
     /* How many companies do we have? */
     $sql = sprintf("SELECT\n                COUNT(*) AS count\n            FROM\n                attachment\n            LEFT JOIN candidate\n                ON attachment.data_item_id = candidate.candidate_id\n                AND attachment.data_item_type = %s\n                AND attachment.site_id = candidate.site_id\n            LEFT JOIN user AS owner_user\n                ON candidate.owner = owner_user.user_id\n            WHERE\n                resume = 1\n            AND\n                %s\n            AND\n                (ISNULL(candidate.is_admin_hidden) OR (candidate.is_admin_hidden = 0))\n            AND\n                (ISNULL(candidate.is_active) OR (candidate.is_active = 1))\n            AND\n                attachment.site_id = %s", DATA_ITEM_CANDIDATE, $this->_WHERE, $this->_siteID);
     $rs = $this->_db->getAssoc($sql);
     /* Pass "Search By Resume"-specific parameters to Pager constructor. */
     parent::__construct($rs['count'], $rowsPerPage, $currentPage);
 }
开发者ID:rankinp,项目名称:OpenCATS,代码行数:61,代码来源:Search.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: sphinx_search

function sphinx_search($query, $offset = 0, $limit = 30)
{
    require_once 'lib/sphinxapi.php';
    $sphinxClient = new SphinxClient();
    $sphinxClient->SetServer('localhost', 9312);
    $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($query, 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);
        }
    }
    return $ids;
}
开发者ID:rclsilver,项目名称:openshift-tt-rss,代码行数:22,代码来源:functions.php

示例14: getRelaCateCommon

 /**
  * 关键词获取普通产品获取相关分类
  * @param array $splitKeywords
  * @return array
  */
 public function getRelaCateCommon($splitKeywords, $cateid = 0, $limit = 20)
 {
     $sphinxConfig = $this->di["config"]["prosearchd"];
     $sphinx = new \SphinxClient();
     $sphinx->SetServer($sphinxConfig['host'], intval($sphinxConfig['port']));
     $sphinx->SetSelect("id, cate3");
     $sphinx->SetFilter("cate3", array(1270), true);
     if ($cateid) {
         $sphinx->SetFilter("cate3", array($cateid), false);
     }
     $sphinx->SetFilterRange("id", 1, 900000000, false);
     $sphinx->SetLimits(0, $limit, $limit);
     $sphinx->SetGroupBy('cate3', SPH_GROUPBY_ATTR, "@count desc");
     $batchResult = $sphinx->query($splitKeywords, "product_distri");
     $error = $sphinx->getLastError();
     if ($error) {
         return array();
     }
     $result = $this->fomatSphinxData($batchResult);
     if (empty($result) || !is_array($result)) {
         $result = array();
     }
     return $result;
 }
开发者ID:tianyunchong,项目名称:php,代码行数:29,代码来源:SearchProToolService.php

示例15: SphinxClient

<?php

/**
 * sphinx链接测试
 */
$offset = 0;
$limit = 30;
include_once "sphinxapi.php";
$sphinx = new SphinxClient();
$sphinx->setServer('192.168.2.188', 9319);
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->SetSortMode(SPH_SORT_EXTENDED, "newstime DESC");
$sphinx->SetFilter('checked', array(1));
$sphinx->SetLimits($offset * 30, $limit, 1000);
$res = $sphinx->query("", 'd_hangyenews,m_hangyenews');
echo "<pre>";
var_dump($sphinx);
echo "\n";
var_dump($res);
exit;
开发者ID:tianyunchong,项目名称:php,代码行数:20,代码来源:info.php


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