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


PHP String::excerpt方法代码示例

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


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

示例1: formatResults

 private function formatResults($results, $terms)
 {
     $highlightOptions = array('format' => '<b>\\1</b>', 'html' => false, 'regex' => "|%s|iu");
     $snippetFields = array('description', 'fulltext', 'abstract');
     // Format the results for the view
     foreach ($results as &$result) {
         // Event for special formatting
         $override = Event::trigger('search.onFormatResult', array($result['hubtype'], &$result, $terms, $highlightOptions));
         // Only allow one override per result
         if (count($override) == 1) {
             $override = $override[0];
         }
         if (empty($override)) {
             //@FIXME: SOLR-specific
             $result['title'] = $result['title'][0];
             // Appends http(s)://
             if (isset($result['url'])) {
                 $result['url'] = rtrim(Request::base(), "/") . $result['url'];
             } else {
                 $result['url'] = '';
             }
             $snippet = '';
             foreach ($result as $field => &$r) {
                 // Only work on strings
                 if (is_string($r)) {
                     $r = strip_tags($r);
                 }
                 // Highlight everything except the URL
                 if ($field != 'url') {
                     $r = \Hubzero\Utility\String::highlight($r, $terms, $highlightOptions);
                 }
                 /** 
                  * Generate the snippet
                  * A snippet is the search result text which is displayed
                  **/
                 if (in_array($field, $snippetFields)) {
                     $snippet .= $r . " ";
                 }
             }
             // Do some filtering
             $snippet = str_replace("\n", '', $snippet);
             $snippet = str_replace("\r", '', $snippet);
             $snippet = str_replace("<br/>", '', $snippet);
             $snippet = str_replace("<br>", '', $snippet);
             $snippet = \Hubzero\Utility\String::excerpt($snippet, $terms, $radius = 200, $ellipsis = '…');
             $result['snippet'] = $snippet;
             if (isset($result['author'])) {
                 $authorCnt = 1;
                 $authorString = '';
                 foreach ($result['author'] as $author) {
                     if ($authorCnt < count($result['author'])) {
                         $authorString .= $author;
                         $authorString .= ',';
                     } else {
                         $authorString .= $author;
                     }
                     $authorCnt++;
                 }
                 $result['authorString'] = $authorString;
             }
         } else {
             $result = $override;
         }
     }
     // End foreach results
     return $results;
 }
开发者ID:kevinwojo,项目名称:hubzero-cms,代码行数:67,代码来源:solr.php

示例2: listTask

 public function listTask()
 {
     $config = Component::params('com_search');
     $query = new \Hubzero\Search\Query($config);
     $terms = Request::getVar('terms', '*:*');
     $limit = Request::getInt('limit', 10);
     $start = Request::getInt('start', 0);
     $sortBy = Request::getVar('sortBy', '');
     $sortDir = Request::getVar('sortDir', '');
     $type = Request::getVar('type', '');
     $filters = Request::getVar('filters', array());
     // Apply the sorting
     if ($sortBy != '' && $sortDir != '') {
         $query = $query->sortBy($sortBy, $sortDir);
     }
     if ($type != '') {
         $query->addFilter('Type', array('hubtype', '=', $type));
     }
     // Administrators can see all records
     $isAdmin = User::authorise('core.admin', 'com_users');
     if ($isAdmin) {
         $query = $query->query($terms)->limit($limit)->start($start);
     } else {
         $query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
     }
     // Perform the query
     $query = $query->run();
     $results = $query->getResults();
     $numFound = $query->getNumFound();
     $highlightOptions = array('format' => '<span class="highlight">\\1</span>', 'html' => false, 'regex' => "|%s|iu");
     foreach ($results as &$result) {
         $snippet = '';
         foreach ($result as $field => &$r) {
             if (is_string($r)) {
                 $r = strip_tags($r);
             }
             if ($field != 'url') {
                 $r = \Hubzero\Utility\String::highlight($r, $terms, $highlightOptions);
             }
             if ($field == 'description' || $field == 'fulltext' || $field == 'abstract') {
                 if (isset($result['description']) && $result['description'] != $result['fulltext']) {
                     $snippet .= $r;
                 }
             }
         }
         $snippet = str_replace("\n", "", $snippet);
         $snippet = str_replace("\r", "", $snippet);
         $snippet = \Hubzero\Utility\String::excerpt($snippet, $terms, $radius = 200, $ellipsis = '…');
         $result['snippet'] = $snippet;
     }
     $response = new stdClass();
     $response->results = $results;
     $response->total = $numFound;
     $response->showing = count($results);
     $response->success = true;
     $this->send($response);
 }
开发者ID:kevinwojo,项目名称:hubzero-cms,代码行数:57,代码来源:searchv1_0.php


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