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


PHP SearchResult::getTextSnippet方法代码示例

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


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

示例1: showHit

 /**
  * Format a single hit result
  *
  * @param SearchResult $result
  * @param array $terms Terms to highlight
  *
  * @return string
  */
 protected function showHit($result, $terms)
 {
     $profile = new ProfileSection(__METHOD__);
     if ($result->isBrokenTitle()) {
         return '';
     }
     $title = $result->getTitle();
     $titleSnippet = $result->getTitleSnippet($terms);
     if ($titleSnippet == '') {
         $titleSnippet = null;
     }
     $link_t = clone $title;
     wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $terms, $this));
     $link = Linker::linkKnown($link_t, $titleSnippet);
     //If page content is not readable, just return the title.
     //This is not quite safe, but better than showing excerpts from non-readable pages
     //Note that hiding the entry entirely would screw up paging.
     if (!$title->userCan('read', $this->getUser())) {
         return "<li>{$link}</li>\n";
     }
     // If the page doesn't *exist*... our search index is out of date.
     // The least confusing at this point is to drop the result.
     // You may get less results, but... oh well. :P
     if ($result->isMissingRevision()) {
         return '';
     }
     // format redirects / relevant sections
     $redirectTitle = $result->getRedirectTitle();
     $redirectText = $result->getRedirectSnippet($terms);
     $sectionTitle = $result->getSectionTitle();
     $sectionText = $result->getSectionSnippet($terms);
     $redirect = '';
     if (!is_null($redirectTitle)) {
         if ($redirectText == '') {
             $redirectText = null;
         }
         $redirect = "<span class='searchalttitle'>" . $this->msg('search-redirect')->rawParams(Linker::linkKnown($redirectTitle, $redirectText))->text() . "</span>";
     }
     $section = '';
     if (!is_null($sectionTitle)) {
         if ($sectionText == '') {
             $sectionText = null;
         }
         $section = "<span class='searchalttitle'>" . $this->msg('search-section')->rawParams(Linker::linkKnown($sectionTitle, $sectionText))->text() . "</span>";
     }
     // format text extract
     $extract = "<div class='searchresult'>" . $result->getTextSnippet($terms) . "</div>";
     $lang = $this->getLanguage();
     // format description
     $byteSize = $result->getByteSize();
     $wordCount = $result->getWordCount();
     $timestamp = $result->getTimestamp();
     $size = $this->msg('search-result-size', $lang->formatSize($byteSize))->numParams($wordCount)->escaped();
     if ($title->getNamespace() == NS_CATEGORY) {
         $cat = Category::newFromTitle($title);
         $size = $this->msg('search-result-category-size')->numParams($cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount())->escaped();
     }
     $date = $lang->userTimeAndDate($timestamp, $this->getUser());
     $fileMatch = '';
     // Include a thumbnail for media files...
     if ($title->getNamespace() == NS_FILE) {
         $img = $result->getFile();
         $img = $img ?: wfFindFile($title);
         if ($result->isFileMatch()) {
             $fileMatch = "<span class='searchalttitle'>" . $this->msg('search-file-match')->escaped() . "</span>";
         }
         if ($img) {
             $thumb = $img->transform(array('width' => 120, 'height' => 120));
             if ($thumb) {
                 $desc = $this->msg('parentheses')->rawParams($img->getShortDesc())->escaped();
                 // Float doesn't seem to interact well with the bullets.
                 // Table messes up vertical alignment of the bullets.
                 // Bullets are therefore disabled (didn't look great anyway).
                 return "<li>" . '<table class="searchResultImage">' . '<tr>' . '<td style="width: 120px; text-align: center; vertical-align: top;">' . $thumb->toHtml(array('desc-link' => true)) . '</td>' . '<td style="vertical-align: top;">' . "{$link} {$redirect} {$section} {$fileMatch}" . $extract . "<div class='mw-search-result-data'>{$desc} - {$date}</div>" . '</td>' . '</tr>' . '</table>' . "</li>\n";
             }
         }
     }
     $html = null;
     $score = '';
     if (wfRunHooks('ShowSearchHit', array($this, $result, $terms, &$link, &$redirect, &$section, &$extract, &$score, &$size, &$date, &$related, &$html))) {
         $html = "<li><div class='mw-search-result-heading'>" . "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" . "<div class='mw-search-result-data'>{$size} - {$date}</div>" . "</li>\n";
     }
     return $html;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:92,代码来源:SpecialSearch.php

示例2: showHit

 /**
  * Format a single hit result
  * @param SearchResult $result
  * @param array $terms terms to highlight
  */
 protected function showHit($result, $terms)
 {
     global $wgContLang, $wgLang, $wgUser;
     wfProfileIn(__METHOD__);
     if ($result->isBrokenTitle()) {
         wfProfileOut(__METHOD__);
         return "<!-- Broken link in search result -->\n";
     }
     $sk = $wgUser->getSkin();
     $t = $result->getTitle();
     $titleSnippet = $result->getTitleSnippet($terms);
     if ($titleSnippet == '') {
         $titleSnippet = null;
     }
     $link_t = clone $t;
     wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $terms, $this));
     $link = $this->sk->linkKnown($link_t, $titleSnippet);
     //If page content is not readable, just return the title.
     //This is not quite safe, but better than showing excerpts from non-readable pages
     //Note that hiding the entry entirely would screw up paging.
     if (!$t->userCanRead()) {
         wfProfileOut(__METHOD__);
         return "<li>{$link}</li>\n";
     }
     // If the page doesn't *exist*... our search index is out of date.
     // The least confusing at this point is to drop the result.
     // You may get less results, but... oh well. :P
     if ($result->isMissingRevision()) {
         wfProfileOut(__METHOD__);
         return "<!-- missing page " . htmlspecialchars($t->getPrefixedText()) . "-->\n";
     }
     // format redirects / relevant sections
     $redirectTitle = $result->getRedirectTitle();
     $redirectText = $result->getRedirectSnippet($terms);
     $sectionTitle = $result->getSectionTitle();
     $sectionText = $result->getSectionSnippet($terms);
     $redirect = '';
     if (!is_null($redirectTitle)) {
         if ($redirectText == '') {
             $redirectText = null;
         }
         $redirect = "<span class='searchalttitle'>" . wfMsg('search-redirect', $this->sk->linkKnown($redirectTitle, $redirectText)) . "</span>";
     }
     $section = '';
     if (!is_null($sectionTitle)) {
         if ($sectionText == '') {
             $sectionText = null;
         }
         $section = "<span class='searchalttitle'>" . wfMsg('search-section', $this->sk->linkKnown($sectionTitle, $sectionText)) . "</span>";
     }
     // format text extract
     $extract = "<div class='searchresult'>" . $result->getTextSnippet($terms) . "</div>";
     // format score
     if (is_null($result->getScore())) {
         // Search engine doesn't report scoring info
         $score = '';
     } else {
         $percent = sprintf('%2.1f', $result->getScore() * 100);
         $score = wfMsg('search-result-score', $wgLang->formatNum($percent)) . ' - ';
     }
     // format description
     $byteSize = $result->getByteSize();
     $wordCount = $result->getWordCount();
     $timestamp = $result->getTimestamp();
     $size = wfMsgExt('search-result-size', array('parsemag', 'escape'), $this->sk->formatSize($byteSize), $wgLang->formatNum($wordCount));
     $date = $wgLang->timeanddate($timestamp);
     // link to related articles if supported
     $related = '';
     if ($result->hasRelated()) {
         $st = SpecialPage::getTitleFor('Search');
         $stParams = array_merge($this->powerSearchOptions(), array('search' => wfMsgForContent('searchrelated') . ':' . $t->getPrefixedText(), 'fulltext' => wfMsg('search')));
         $related = ' -- ' . $sk->linkKnown($st, wfMsg('search-relatedarticle'), array(), $stParams);
     }
     // Include a thumbnail for media files...
     if ($t->getNamespace() == NS_FILE) {
         $img = wfFindFile($t);
         if ($img) {
             $thumb = $img->transform(array('width' => 120, 'height' => 120));
             if ($thumb) {
                 $desc = $img->getShortDesc();
                 wfProfileOut(__METHOD__);
                 // Float doesn't seem to interact well with the bullets.
                 // Table messes up vertical alignment of the bullets.
                 // Bullets are therefore disabled (didn't look great anyway).
                 return "<li>" . '<table class="searchResultImage">' . '<tr>' . '<td width="120" align="center" valign="top">' . $thumb->toHtml(array('desc-link' => true)) . '</td>' . '<td valign="top">' . $link . $extract . "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" . '</td>' . '</tr>' . '</table>' . "</li>\n";
             }
         }
     }
     wfProfileOut(__METHOD__);
     return "<li>{$link} {$redirect} {$section} {$extract}\n" . "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" . "</li>\n";
 }
开发者ID:BackupTheBerlios,项目名称:swahili-dict,代码行数:96,代码来源:SpecialSearch.php

示例3: getTextSnippet

 function getTextSnippet($terms)
 {
     if (is_null($this->mHighlightText)) {
         return parent::getTextSnippet($terms);
     }
     return $this->mHighlightText;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:7,代码来源:MWSearch_body.php


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