function OnPageLoad() { echo new XhtmlElement('h1', $this->GetPageTitle()); # If no search term, show a search form (intended for mobile) if (!$this->query instanceof SearchQuery) { ?> <form action="/search" method="get"><div> <input type="search" name="q" /> <input type="submit" value="Search" /> </div></form> <?php return; } if ($this->paging->GetTotalResults()) { # write the paging navbar $paging_bar = $this->paging->GetNavigationBar(); echo $paging_bar; # Load files used for custom formats require_once 'email/email-address-protector.class.php'; require_once 'search/search-highlighter.class.php'; $protector = new EmailAddressProtector($this->GetSettings()); $highlighter = new SearchHighlighter(); echo '<dl class="search">'; foreach ($this->results as $result) { /* @var $result SearchItem */ echo '<dt>'; $title = htmlentities($result->Title(), ENT_QUOTES, "UTF-8", false); $title = $highlighter->Highlight($this->query->GetSanitisedTerms(), $title); echo '<a href="' . htmlentities($result->Url(), ENT_QUOTES, "UTF-8", false) . '">' . $title . "</a> "; echo "</dt>"; echo '<dd>'; $description = htmlentities($result->Description(), ENT_QUOTES, "UTF-8", false); $description = $protector->ApplyEmailProtection($description, AuthenticationManager::GetUser()->IsSignedIn()); $description = $highlighter->Highlight($this->query->GetSanitisedTerms(), $description); echo "<p>" . $description . "</p>"; echo $result->RelatedLinksHtml(); echo '<p class="url">' . htmlentities($this->DisplayUrl($result->Url()), ENT_QUOTES, "UTF-8", false) . "</p>"; if (isset($_GET['debug'])) { echo '<ul class="weight">' . '<li>Matched field weight: <strong>' . $result->WeightOfMatchedField() . '</strong></li>' . '<li>Weight of result type: <strong>' . $result->WeightOfType() . '</strong></li>' . '<li>Weight within type: <strong>' . $result->WeightWithinType() . '</strong></li>' . '<li>Weight: <strong>' . $result->Weight() . '</strong></li>' . '</ul>'; } echo "</dd>"; } echo '</dl>'; echo $paging_bar; } else { ?> <p>Sorry, we didn't find anything matching your search.</p> <p>Please check your spelling, or try rewording your search.</p> <p>If you still can't find what you're looking for, please <a href="/contact/"> contact us</a>.</p> <?php } $this->AddSeparator(); $this->BuySomething(); }
/** * @param $terms Array: terms to highlight * @return String: highlighted text snippet, null (and not '') if not supported */ function getTextSnippet($terms) { global $wgUser, $wgAdvancedSearchHighlighting; $this->initText(); list($contextlines, $contextchars) = SearchEngine::userHighlightPrefs($wgUser); $h = new SearchHighlighter(); if ($wgAdvancedSearchHighlighting) { return $h->highlightText($this->mText, $terms, $contextlines, $contextchars); } else { return $h->highlightSimple($this->mText, $terms, $contextlines, $contextchars); } }
/** * @param array $terms terms to highlight * @return String: highlighted text snippet, null (and not '') if not supported */ function getTextSnippet($terms) { global $wgUser, $wgAdvancedSearchHighlighting; $this->initText(); // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter. list($contextlines, $contextchars) = SearchEngine::userHighlightPrefs($wgUser); $h = new SearchHighlighter(); if ($wgAdvancedSearchHighlighting) { return $h->highlightText($this->mText, $terms, $contextlines, $contextchars); } else { return $h->highlightSimple($this->mText, $terms, $contextlines, $contextchars); } }
/** * Emulates SearchEngine getTextSnippet so that we can use our own userHighlightPrefs * (only needed until userHighlightPrefs in SearchEngine is fixed) * * @param $terms array of terms to highlight * @return string highlighted text snippet */ function getTextSnippet( $terms ) { global $wgUser, $wgAdvancedSearchHighlighting; global $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index; $this->initText(); list( $contextlines, $contextchars ) = SphinxMWSearch::userHighlightPrefs( $wgUser ); if ( $wgSphinxSearchMWHighlighter ) { $h = new SearchHighlighter(); if ( $wgAdvancedSearchHighlighting ) { return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars ); } else { return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars ); } } $excerpts_opt = array( "before_match" => "(searchmatch)", "after_match" => "(/searchmatch)", "chunk_separator" => " ... ", "limit" => $contextlines * $contextchars, "around" => $contextchars, ); $excerpts = $this->sphinx_client->BuildExcerpts( array( $this->mText ), $wgSphinxSearch_index, join( ' ', $terms ), $excerpts_opt ); if ( is_array( $excerpts ) ) { $ret = ''; foreach ( $excerpts as $entry ) { // remove some wiki markup $entry = preg_replace( '/([\[\]\{\}\*\#\|\!]+|==+|<br ?\/?>)/', ' ', $entry ); $entry = str_replace( array("<", ">"), array("<", ">"), $entry ); $entry = str_replace( array( "(searchmatch)", "(/searchmatch)" ), array( "<span class='searchmatch'>", "</span>" ), $entry ); $ret .= "<div style='margin: 0.2em 1em 0.2em 1em;'>$entry</div>\n"; } } else { $ret = wfMsg( 'internalerror_info', $this->sphinx_client->GetLastError() ); } return $ret; }