r50282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50281‎ | r50282 | r50283 >
Date:21:05, 6 May 2009
Author:rainman
Status:ok
Tags:
Comment:
Follow-up for r50207: mysql won't estimate total number of hits, so don't show it - copied from SpecialSearchOld more or less.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -208,19 +208,26 @@
209209
210210
211211 // Get number of results
212 - $titleMatchesSQL = $titleMatches ? $titleMatches->numRows() : 0;
213 - $textMatchesSQL = $textMatches ? $textMatches->numRows() : 0;
 212+ $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
 213+ $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
214214 // Total initial query matches (possible false positives)
215 - $numSQL = $titleMatchesSQL + $textMatchesSQL;
 215+ $num = $titleMatchesNum + $textMatchesNum;
 216+
216217 // Get total actual results (after second filtering, if any)
217218 $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
218 - $titleMatches->getTotalHits() : $titleMatchesSQL;
 219+ $titleMatches->getTotalHits() : $titleMatchesNum;
219220 $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
220 - $textMatches->getTotalHits() : $textMatchesSQL;
221 - $totalRes = $numTitleMatches + $numTextMatches;
 221+ $textMatches->getTotalHits() : $textMatchesNum;
222222
 223+ // get total number of results if backend can calculate it
 224+ $totalRes = 0;
 225+ if($titleMatches && !is_null( $titleMatches->getTotalHits() ) )
 226+ $totalRes += $titleMatches->getTotalHits();
 227+ if($textMatches && !is_null( $textMatches->getTotalHits() ))
 228+ $totalRes += $textMatches->getTotalHits();
 229+
223230 // show number of results and current offset
224 - $wgOut->addHTML( $this->formHeader($term, $numSQL, $totalRes));
 231+ $wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
225232
226233 $wgOut->addHtml( "<div class='searchresults'>" );
227234
@@ -234,11 +241,11 @@
235242 }
236243
237244 // prev/next links
238 - if( $numSQL || $this->offset ) {
 245+ if( $num || $this->offset ) {
239246 $prevnext = wfViewPrevNext( $this->offset, $this->limit,
240247 SpecialPage::getTitleFor( 'Search' ),
241248 wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ),
242 - max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit
 249+ max( $titleMatchesNum, $textMatchesNum ) < $this->limit
243250 );
244251 //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
245252 wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
@@ -274,15 +281,15 @@
275282
276283 $textMatches->free();
277284 }
278 - if( $totalRes === 0 ) {
 285+ if( $num === 0 ) {
279286 $wgOut->addWikiMsg( 'search-nonefound' );
280287 }
281288 $wgOut->addHtml( "</div>" );
282 - if( $totalRes === 0 ) {
 289+ if( $num === 0 ) {
283290 $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() );
284291 }
285292
286 - if( $numSQL || $this->offset ) {
 293+ if( $num || $this->offset ) {
287294 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
288295 }
289296 wfProfileOut( __METHOD__ );
@@ -663,7 +670,7 @@
664671 "</script>";
665672 }
666673
667 - protected function formHeader( $term, $resultsShown, $totalRes ) {
 674+ protected function formHeader( $term, $resultsShown, $totalNum ) {
668675 global $wgContLang, $wgCanonicalNamespaceNames, $wgLang;
669676
670677 $sep = '&nbsp;&nbsp;&nbsp;';
@@ -726,14 +733,19 @@
727734 }
728735 $out .= Xml::closeElement('div') ;
729736
730 - if( $totalRes > 0){
731 - $countHtml = wfMsgExt('showingresultsheader', array( 'parseinline' ),
732 - $this->offset+1, $this->offset+$resultsShown, $totalRes, $term, $resultsShown );
733 - $out .= "<p>{$countHtml}</p>\n" ;
734 - } else{
 737+ if ( $resultsShown > 0 ) {
 738+ if ( $totalNum > 0 ){
 739+ $top = wfMsgExt('showingresultsheader', array( 'parseinline' ),
 740+ $this->offset+1, $this->offset+$resultsShown, $totalNum, $term, $resultsShown );
 741+ } elseif ( $resultsShown >= $this->limit ) {
 742+ $top = wfShowingResults( $this->offset, $this->limit );
 743+ } else {
 744+ $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown );
 745+ }
 746+ $out .= "<p>{$top}</p>\n";
 747+ } else
735748 $out .= "<p>&nbsp;</p>\n";
736 - }
737 -
 749+
738750 $out .= Xml::closeElement('div') ;
739751
740752 return $out;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r50207Redesign of the "new search UI" per Trevor's design plans from usability wiki:...rainman23:07, 4 May 2009

Status & tagging log