Revision: 50282 Author: rainman Date: 2009-05-06 21:05:52 +0000 (Wed, 06 May 2009)
Log Message: ----------- 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: trunk/phase3/includes/specials/SpecialSearch.php =================================================================== --- trunk/phase3/includes/specials/SpecialSearch.php 2009-05-06 20:34:07 UTC (rev 50281) +++ trunk/phase3/includes/specials/SpecialSearch.php 2009-05-06 21:05:52 UTC (rev 50282) @@ -208,19 +208,26 @@ // Get number of results - $titleMatchesSQL = $titleMatches ? $titleMatches->numRows() : 0; - $textMatchesSQL = $textMatches ? $textMatches->numRows() : 0; + $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0; + $textMatchesNum = $textMatches ? $textMatches->numRows() : 0; // Total initial query matches (possible false positives) - $numSQL = $titleMatchesSQL + $textMatchesSQL; + $num = $titleMatchesNum + $textMatchesNum; + // Get total actual results (after second filtering, if any) $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ? - $titleMatches->getTotalHits() : $titleMatchesSQL; + $titleMatches->getTotalHits() : $titleMatchesNum; $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ? - $textMatches->getTotalHits() : $textMatchesSQL; - $totalRes = $numTitleMatches + $numTextMatches; + $textMatches->getTotalHits() : $textMatchesNum; + // get total number of results if backend can calculate it + $totalRes = 0; + if($titleMatches && !is_null( $titleMatches->getTotalHits() ) ) + $totalRes += $titleMatches->getTotalHits(); + if($textMatches && !is_null( $textMatches->getTotalHits() )) + $totalRes += $textMatches->getTotalHits(); + // show number of results and current offset - $wgOut->addHTML( $this->formHeader($term, $numSQL, $totalRes)); + $wgOut->addHTML( $this->formHeader($term, $num, $totalRes)); $wgOut->addHtml( "<div class='searchresults'>" ); @@ -234,11 +241,11 @@ } // prev/next links - if( $numSQL || $this->offset ) { + if( $num || $this->offset ) { $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'Search' ), wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ), - max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit + max( $titleMatchesNum, $textMatchesNum ) < $this->limit ); //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" ); wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) ); @@ -274,15 +281,15 @@ $textMatches->free(); } - if( $totalRes === 0 ) { + if( $num === 0 ) { $wgOut->addWikiMsg( 'search-nonefound' ); } $wgOut->addHtml( "</div>" ); - if( $totalRes === 0 ) { + if( $num === 0 ) { $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() ); } - if( $numSQL || $this->offset ) { + if( $num || $this->offset ) { $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" ); } wfProfileOut( __METHOD__ ); @@ -663,7 +670,7 @@ "</script>"; } - protected function formHeader( $term, $resultsShown, $totalRes ) { + protected function formHeader( $term, $resultsShown, $totalNum ) { global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; $sep = ' '; @@ -726,14 +733,19 @@ } $out .= Xml::closeElement('div') ; - if( $totalRes > 0){ - $countHtml = wfMsgExt('showingresultsheader', array( 'parseinline' ), - $this->offset+1, $this->offset+$resultsShown, $totalRes, $term, $resultsShown ); - $out .= "<p>{$countHtml}</p>\n" ; - } else{ + if ( $resultsShown > 0 ) { + if ( $totalNum > 0 ){ + $top = wfMsgExt('showingresultsheader', array( 'parseinline' ), + $this->offset+1, $this->offset+$resultsShown, $totalNum, $term, $resultsShown ); + } elseif ( $resultsShown >= $this->limit ) { + $top = wfShowingResults( $this->offset, $this->limit ); + } else { + $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown ); + } + $out .= "<p>{$top}</p>\n"; + } else $out .= "<p> </p>\n"; - } - + $out .= Xml::closeElement('div') ; return $out; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs